例如,用户键入!set_channel abc,我如何从客户端获取abc并将其设置为可变的ive,但似乎无法在python中找到解决方法
答案 0 :(得分:0)
好吧,如果您知道用户输入了!set_channel
,那么我假设这意味着您已经掌握了整个消息。如果是这样,您可以只使用split()
方法并采用第二个元素,就像这样。
message = "!set_channel abc" # Replace with a function call that gets the discord message
argument = message.split(" ")[1] # Will get "abc". We use 1 as the index because 0 is for the first element
split方法将获取一个字符串,然后通过传递给该方法的字符串将其“拆分”为其他字符串。我们在空格" "
中传递,消息为!set_channel abc
。因此,当我们调用message.split(" ")
时,它将返回["!set_channel", "abc"]
,而当我们使用索引1时,它将得到它的“ abc”部分。
答案 1 :(得分:0)
您可以仅使用abc作为discord命令的输入。
@client.command()
async def set_channel(ctx, variable):
pass