【发布时间】:2021-02-07 22:23:07
【问题描述】:
尝试向用户发送 PM 但没有任何效果:
async def main_loop():
await bot.wait_until_ready()
while not bot.is_closed():
# do stuff...
if some_random_condition:
user = bot.get_user(user_id)
user.send_message("some message") # doesn't work, user is Nonetype, id is correct though
bot.loop.create_task(main_loop())
bot.run(DISCORD_TOKEN)
由于这只是一个循环函数,我实际上并没有通过 discord.py 的框架传入的上下文或消息对象,我只有机器人 - 但我不知道如何使用机器人来访问用户向他们发送 PM。
【问题讨论】:
-
你必须更精确,说“没有任何效果”太模糊了
-
我在那里的评论说“用户是Nonetype”,我的意思是
bot.get_user(user_id)返回None,所以当我执行user.send_message时,它会出错,因为它是None。 -
您是否启用了intents.members?
标签: python-3.x bots discord.py