分别获取多个参数(C# discord bot 0.9.6)
getting multiple parameters separately (C# discord bot 0.9.6)
所以我想做的是我希望我的机器人能够有两个不同的参数。就像我的意思是我可以提取它的某个部分,然后在有一个“,”或另一个符号之后我可以单独提取以下内容。所以我从一个输入中得到两个不同的字符串。所以就像我有两个字符串,我希望其中一个作为上半部分,第二个作为其余部分。而且我不打算更新到 1.0,所以请告诉我是否不能在 0.9.6 中更新。
你的问题不是很清楚,但我想我知道你在找什么。这是 C# 的一般答案,因为我不知道 Discord 接口有何不同。您似乎正在接受字符串形式的输入,例如:play *songname*,*channelname*
。要将此字符串拆分为您要使用的两个输入 String.Split(',')
一个例子是这样的:
string stringTakenFromDiscord = "play *songname*,*channelname*";
String[] input = stringTakenFromDiscord.Split(',');
//input[0] will be equal to what comes before the comma
//if you were to print it, it would be "play *songname*"
//input[1] will be what comes after the comma
//if you were to print it, it would be "*channelname*"
现在您可以使用数组 input[]
中的任一值做任何您想做的事情,并通过您的代码提供它们以解析它们。请注意,当它按字符拆分时,该字符不会出现在任何一个输出字符串中。这仅适用于只有一个所选字符实例的输入。你可以把角色改成任何你想要的。
我突然想到,将输入改为分两行进行可能更容易。
所以我想做的是我希望我的机器人能够有两个不同的参数。就像我的意思是我可以提取它的某个部分,然后在有一个“,”或另一个符号之后我可以单独提取以下内容。所以我从一个输入中得到两个不同的字符串。所以就像我有两个字符串,我希望其中一个作为上半部分,第二个作为其余部分。而且我不打算更新到 1.0,所以请告诉我是否不能在 0.9.6 中更新。
你的问题不是很清楚,但我想我知道你在找什么。这是 C# 的一般答案,因为我不知道 Discord 接口有何不同。您似乎正在接受字符串形式的输入,例如:play *songname*,*channelname*
。要将此字符串拆分为您要使用的两个输入 String.Split(',')
一个例子是这样的:
string stringTakenFromDiscord = "play *songname*,*channelname*";
String[] input = stringTakenFromDiscord.Split(',');
//input[0] will be equal to what comes before the comma
//if you were to print it, it would be "play *songname*"
//input[1] will be what comes after the comma
//if you were to print it, it would be "*channelname*"
现在您可以使用数组 input[]
中的任一值做任何您想做的事情,并通过您的代码提供它们以解析它们。请注意,当它按字符拆分时,该字符不会出现在任何一个输出字符串中。这仅适用于只有一个所选字符实例的输入。你可以把角色改成任何你想要的。
我突然想到,将输入改为分两行进行可能更容易。