Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用discord bot从Python中的用户处获取参数_Python_Discord.py - Fatal编程技术网

如何使用discord bot从Python中的用户处获取参数

如何使用discord bot从Python中的用户处获取参数,python,discord.py,Python,Discord.py,例如用户类型!设置频道abc如何从客户端获取abc并将其设置为变量我环顾了四周,但似乎无法在python中找到解决方案如果您知道用户键入了!设置频道,我假设这意味着你拥有全部信息。如果是这样的话,您可以使用split()方法并获取第二个元素,如下所示 message = "!set_channel abc" # Replace with a function call that gets the discord message argument = message.split

例如用户类型!设置频道abc如何从客户端获取abc并将其设置为变量我环顾了四周,但似乎无法在python中找到解决方案如果您知道用户键入了
!设置频道
,我假设这意味着你拥有全部信息。如果是这样的话,您可以使用
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方法将获取一个字符串,并通过传递给该方法的字符串将其“拆分”为一组其他字符串。我们传入了一个空格
,消息是
!设置频道abc
。因此,当我们调用
message.split(“”
时,它返回
[“!set_channel”,“abc”]
,当我们使用索引1时,我们得到它的“abc”部分。

您可以使用abc作为discord命令的输入

@client.command()
async def set_channel(ctx, variable):
    pass

欢迎来到堆栈溢出。请阅读如何问好。确保你的问题涵盖以下3个要素:1。问题陈述2。您的代码(应该是3.错误消息(最好是完整的回溯,以帮助其他人查看和提供反馈)。有时可能已经问过相同的问题。请确保您的问题不是错误消息