简体   繁体   中英

Issue with sending dm messages discord.py

I have a command in my bot that allows a user to dm an anonymous message to me. However, when I tested the command my bot only sends the first word of the message to me.

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

You need to add a * if you want to catch the entire phrase. View the docs here about using this and have a look at the example working beneath the code.

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

使用 * 和 args

Also, unless you are using an older version of discord.py, user ids are int s .

maxid = await self.bot.fetch_user(584500826450427906)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM