构建一个Discord机器人来DM特定用户-AttributeError:'NoneType'对象没有属性'send'

胡多尔

一般来说,我是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'

希望我能就如何解决这个问题提供一些建议!

ŁukaszKwieciński

您正在尝试的用户很简单None,nonetype没有任何属性,为了解决您需要启用intent的问题,这就是

还要记住,您需要这样做,intents.members因此还需要在开发人员门户中启用它们,第一个链接中也提供了指南。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

AttributeError: 'NoneType' 对象没有属性 'send'

Discord.py | 尝试dm用户并获取AttributeError:'NoneType'对象没有属性'send'

AttributeError: 'NoneType' 对象没有属性 'send' pigpiod

AttributeError:“NoneType”对象没有属性“send_keys”

Discord.py AttributeError("'NoneType' 对象没有属性 'roles'")

Discord.py AttributeError: 'NoneType' 对象没有属性 'guild'

我的不和谐机器人给了我 AttributeError("'NoneType' 对象没有属性 'roles'")

Discord.py 'NoneType' 对象没有属性 'send'

Selenium Python AttributeError:“ NoneType”对象没有属性“ send_keys”

我为什么会收到“ AttributeError:'NoneType'对象没有属性'send'的错误

Discordpy 在 var 更改时发送 dms 但获取 AttributeError: 'NoneType' 对象没有属性 'send'

AttributeError:'NoneType'对象没有属性'tbody'

AttributeError: 'NoneType' 对象没有属性 'group'

AttributeError: 'NoneType' 对象没有属性 'asfreq'

“ AttributeError:'NoneType'对象没有属性'insert'”

AttributeError:'NoneType'对象没有属性'update'

AttributeError:'NoneType'对象没有属性'text'?

AttributeError:'NoneType'对象没有属性'current'

AttributeError:'NoneType'对象没有属性'loader'

AttributeError: 'NoneType' 对象没有属性 '...'

AttributeError:'NoneType'对象没有属性'split'

AttributeError:'NoneType'对象没有属性'endswith'

AttributeError:'NoneType'对象没有属性'roles'

AttributeError:“ NoneType”对象没有属性“ _root”

AttributeError:“ NoneType”对象没有属性

AttributeError:“ NoneType”对象没有属性“ strip”

AttributeError: 'NoneType' 对象没有属性 'scenePos'

AttributeError: 'NoneType' 对象没有属性 'foo'

AttributeError:“ NoneType”对象没有属性“ dtype”