本文介绍了如何使用机器人 DM 所有人 - discord.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
限时送ChatGPT账号..
嗯,我正在使用直接消息功能向特定用户发送消息,但我一直在寻找方法,以便可以向服务器上的每个人发送消息,但我不明白.我使用 discord.py 0.16.9 作为参考.这是我当前的代码:
Well, I'm doing a Direct Message function to DM a specific user, but I've been searching the way to do it so I can message everyone on a server, and I don't get it. I'm using discord.py 0.16.9 for reference. Here is my current code:
@client.command(pass_context = True)
async def dm(ctx, member : discord.Member = None, *, message):
if not ctx.message.author.server_permissions.administrator:
return
if not member:
return await client.say(ctx.message.author.mention + "Specify a user to DM!")
if member = "@everyone":
member =
else:
await client.send_message(member, message)
推荐答案
正如评论中已经说明的那样,对所有人进行 dm 确实不是一个好主意,但如果必须,您可以遍历服务器的所有成员并单独向他们发送消息.在您的示例中:
As already stated in a comment, it really isn't a good idea to dm everyone, but if you must, you can iterate over all members of a server and message them individually. In your example:
if member == "@everyone":
for server_member in ctx.message.server.members:
await client.send_message(server_member, message)
这篇关于如何使用机器人 DM 所有人 - discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!