发送 dm 消息 discord.py 的问题

时间:2021-02-02 01:10:42

标签: python python-3.x discord.py

我的机器人中有一个命令,允许用户向我发送匿名消息。但是,当我测试命令时,我的机器人只向我发送消息的第一个单词。

    @commands.command(name='msgetika', aliases=['msgmax'])
    async def msgetika(self, ctx, message1=None):
        '''Send an annonymous message to maxhatt3r'''
        if message1 is None:
            await ctx.send('Please specify a message')

        maxid = await self.bot.fetch_user('584500826450427906')
        await maxid.send('Anonymous message: ' + message1)
        msg = await ctx.send('Sending message to max.')

        await ctx.message.delete()
        await asyncio.sleep(5)

        await msg.delete()

1 个答案:

答案 0 :(得分:1)

如果您想捕捉整个短语,您需要添加一个 *View the docs here 关于如何使用它并查看代码下方的示例。

   @commands.command(name='msgetika', aliases=['msgmax'])
    async def msgetika(self, ctx, *, message1=None):

using * and args

此外,除非您使用旧版本的 discord.py,否则user ids are ints

maxid = await self.bot.fetch_user(584500826450427906)