【发布时间】:2021-10-23 18:49:33
【问题描述】:
我正在尝试向服务器的所有成员发送 dm。我正在使用的代码没有错误,但它不起作用。
@bot.command(pass_context=True)
async def dm(ctx, *, message):
for user in ctx.guild.members:
try:
await user.send(message)
print(f"Sent {user.name} a DM.")
except:
print(f"Couldn't DM {user.name}.")
print("Sent all the server a DM.")
【问题讨论】:
-
您能否将
except替换为except Exception as e: print(e)并发布输出?另外 - 您是否设置了所需的意图? -
我更换了,它是 sintax 错误
-
我想这不言自明
-
好的,现在可以了。输出:400 Bad Request(错误代码:50007):无法向该用户发送消息
-
是的,这可能是机器人本身,您不能向自己发送 DM。您是否设置了必要的意图?
标签: python discord discord.py bots