java dm短信,无法发送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: .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: .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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值