Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.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
Python Discord.py Cog无法接受内容参数_Python_Discord.py - Fatal编程技术网

Python Discord.py Cog无法接受内容参数

Python Discord.py Cog无法接受内容参数,python,discord.py,Python,Discord.py,所以我现在在discord.py中,每当我直接编辑bot.py(我的主文件)时,我都可以实现一个版本的suggest命令 @bot.command(name = 'suggest', help = 'Use this command to give a suggestion to the server') async def suggest(ctx, content): channel = discord.utils.get(bot.guilds[0].channels, name =

所以我现在在discord.py中,每当我直接编辑bot.py(我的主文件)时,我都可以实现一个版本的suggest命令

@bot.command(name = 'suggest', help = 'Use this command to give a suggestion to the server')
async def suggest(ctx, content):
    channel = discord.utils.get(bot.guilds[0].channels, name = 'suggestions')
    print('Suggest command triggered, content is {}'.format(content))
    await channel.send(content)
^bot只是我的客户端版本

这非常好(除了我只得到第一个单词的内容,所以如果有人能解决这个问题,那也很好)

但当我复制粘贴到我的齿轮

    @commands.command(name = 'suggest', help = 'Use this command to give a suggestion to the server')
    async def suggest(self, bot, ctx, content):
        print('Suggest command triggered')
        channel = discord.utils.get(bot.guilds[0].channels, name = 'suggestions')
        print('Content is {}'.format(content))
        await channel.send(content)

它不工作,有人能帮我吗?

对于cog来说,
bot
参数是不必要的,所以您只需要

    @commands.command(name = 'suggest', help = 'Use this command to give a suggestion to the server')
    async def suggest(self, ctx, content):
        print('Suggest command triggered')
        channel = discord.utils.get(bot.guilds[0].channels, name = 'suggestions')
        print('Content is {}'.format(content))
        await channel.send(content)
对于只包含第一个单词的参数,discord.py按单词分隔参数,因此您可以使用
*
将它们分组,如下所示:

    async def suggest(self, ctx, *content):  # gets all the words in a tuple