如何使机器人 DM 成为人员列表?(Discord.py) (重写) [英] How to make a bot DM a list of people? (Discord.py) (Rewrite)
问题描述
所以这会向我@提及的任何人发送 DM.
So this sends a DM to whoever I @mention.
@bot.command(pass_context=True)
async def pm(ctx, user: discord.User):
await user.send('hello')
我如何更改它以在文本文件或包含用户 ID 的列表变量中发送 ID 列表?
How could I change this to message a list of IDs in let's say a text file, or a list variable containing user IDs?
换句话说,我如何用一个命令向多个人发送消息?
In other words, how can I message multiple people with one command?
推荐答案
你可以使用 Client.get_user_info
获取指定 id 值的 User
类(如果存在).
You can use Client.get_user_info
to get the User
class for a specified id value, if it exists.
这是一个如何做到这一点的示例.
Here is an example of how this can be done.
@bot.command()
async def pm(ctx):
user_id_list = [1, 2, 3] # Replace this with list of IDs
for user_id in user_id_list:
user = await bot.get_user_info(user_id)
await user.send('hello')
另外请注意,您不需要 pass_context=True
,因为上下文总是在 discord.py
的重写版本中传递.见这里:https://discordpy.readthedocs.io/en/rewrite/migrating.html#context-changes
Also note that you do not need pass_context=True
as context is always passed in the rewrite version of discord.py
. See here: https://discordpy.readthedocs.io/en/rewrite/migrating.html#context-changes
这篇关于如何使机器人 DM 成为人员列表?(Discord.py) (重写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!