一般来说,我是discord.py和Python编程的新手。我正在尝试编写一种机器人,该机器人可以通过对on_message
事件做出反应来DM用户(例如,键入“发送DM”,然后将DM发送给该特定人员)。但是,当我尝试吸引用户时,结果为:AttributeError:'NoneType' object has no attribute 'send'
。我的猜测是,它必须与我要接受的人的身份证有关,但我不知道这有什么问题。即使我确定这个ID确实存在(我不能复制错误的ID,也可以吗?右键单击用户名,然后在列表末尾显示“ Copy ID”选项。) 。)如果我让漫游器将DM发送给消息的作者(即我本人),则完全可以正常工作(也许是因为代码不涉及获取ID。)
这是我的代码:
@client.event
async def on_message(message):
content = message.content
if message.author == client.user:
return
#DM'd users
if content == 'send a DM!':
user = client.get_user(<the user's ID here, it's an int>)
await user.send('hello')
await message.author.send('hello') #it works when sending myself a DM
await client.process_command(message)
通知我出现错误的完整响应是:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\X100e\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "c:/Users/X100e/Documents/code/Python/bot.py", line 73, in on_message
await user.send('hello')
AttributeError: 'NoneType' object has no attribute 'send'
希望我能就如何解决这个问题提供一些建议!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句