【发布时间】:2020-07-21 13:14:10
【问题描述】:
我正在尝试使用自我机器人与自己联系。我正在尝试在我的代码中使用get_user() 函数。
bot = commands.Bot(command_prefix='', self_bot=True)
counter = 0
userID = 695724603406024726
@bot.event
async def dm(userID):
print('Running Function')
global counter
if counter <= 0:
print('Finding user.')
counter += 1
user = bot.get_user(userID)
print('user:',user)
await user.send("Hello")
print('message sent')
return
bot.loop.create_task(dm(userID))
bot.run(token, bot=False)
相反,我返回此错误:
File "<ipython-input-1-90e5e962a6e9>", line 24, in dm
await user.send("Hello")
AttributeError: 'NoneType' object has no attribute 'send'
机器人找不到用户并返回一个None 值。我已经测试了多个 ID,但不确定是什么问题。
【问题讨论】:
-
它告诉你你的
user对象没有send方法。您是否确认此方法存在于您从中派生的任何包中? -
@Chris 用户对象必须是不和谐对象。我正在尝试从 get_user 函数中获取它。它并没有告诉我它没有发送方法,而是告诉我找不到用户因此弹出 NoneType 错误。
标签: python discord.py