问题描述
因此,这会将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?
推荐答案
您可以使用以获得 User
类指定的id值(如果存在)。
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
,因为上下文始终在<$ c $的重写版本中传递c> discord.py 。参见此处:
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
这篇关于如何使bot DM成为人员列表? (Discord.py)(重写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!