如何使bot DM成为人员列表? (Discord.py)(重写) [英] How to make a bot DM a list of people? (Discord.py) (Rewrite)

查看:75
本文介绍了如何使bot DM成为人员列表? (Discord.py)(重写)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,这会将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 以获得 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 。参见此处: 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

这篇关于如何使bot DM成为人员列表? (Discord.py)(重写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆