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

时间:2020-03-18 01:14:58

标签: python discord.py

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

@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)

^机器人只是我的客户端版本

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

但是当我将粘贴复制到我的齿轮中

    @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)

无效,有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

对于齿轮来说,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