How to DM everyone with a bot - discord.py(如何使用机器人 DM 所有人 - discord.py)
问题描述
嗯,我正在使用直接消息功能向特定用户发送消息,但我一直在寻找方法,以便可以向服务器上的每个人发送消息,但我不明白.我使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用机器人 DM 所有人 - discord.py


基础教程推荐
- 筛选NumPy数组 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01