无法发送DM消息(Discord bot)

我需要通过帮助Discord bot向用户发送私信 .

使用Django Python .

文件路径> discordbot(django app)/management/commands/trades.py

即我跑 python manage.py trades

class Command(BaseCommand):
    def handle(self, *args, **options):

        client = Bot(description="LivePage", command_prefix="-", pm_help = False)

        async def send_order():
            await client.wait_until_ready()
            counter = 0
            while not client.is_closed:
                user = discord.Object(id = '415618634120167424') # i get my id with using command in the discord client - \@ + nickname 
                await client.send_message(user, 'milkiii') 
            await asyncio.sleep(5) # task runs every 60 seconds

        @client.event
        async def on_ready():
        print('Use this link to invite {}:'.format(client.user.name))

        client.loop.create_task(send_order())       
        client.run()

但是当脚本运行时,我有下一条消息:

Task exception was never retrieved
future: <Task finished coro=<Command.handle.<locals>.send_order() done, defined at /home/worksection/worksection/botdiscord/management/commands/trades.py:24> exception=NotFound('NOT FOUND (status code: 404): Unknown Channel',)>
Traceback (most recent call last):
  File "/home/worksection/worksection/botdiscord/management/commands/trades.py", line 41, in send_order
    await client.send_message(user, 'milkiii')
  File "/home/worksection/env/lib/python3.6/site-packages/discord/client.py", line 1152, in send_message
    data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
  File "/home/worksection/env/lib/python3.6/site-packages/discord/http.py", line 198, in request
    raise NotFound(r, data)
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Channel

如果我将 await client.send_message(user, 'milkiii') 更改为> await client.send_message(415618634120167424, 'milkiii')

我会看到下一个错误:

Task exception was never retrieved
future: <Task finished coro=<Command.handle.<locals>.send_order() done, defined at /home/worksec
/worksection/botdiscord/management/commands/trades.py:24> exception=InvalidArgument('Destination
t be Channel, PrivateChannel, User, or Object. Received int',)>
Traceback (most recent call last):
  File "/home/worksection/worksection/botdiscord/management/commands/trades.py", line 41, in sen
der
    await client.send_message(415618634120167424, 'milkiii')
  File "/home/worksection/env/lib/python3.6/site-packages/discord/client.py", line 1145, in send
sage
    channel_id, guild_id = yield from self._resolve_destination(destination)
  File "/home/worksection/env/lib/python3.6/site-packages/discord/client.py", line 289, in _reso
destination
    raise InvalidArgument(fmt.format(destination))
discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Re
ed int

你能帮助我吗? <

回答(0)