如何使discord bot检查您是什么服务器?

2024-04-27 01:01:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个discord检查机器人(python)。 bot应该能够看到个人在哪些服务器上,因为在授权时有一个权限。 当与命令“chk!check(memberName)”一起使用时,bot应以如下方式响应:

Servers that (memberName) is in:
Server1
Server2
Server3
Server4

现在,我已经完成了大部分工作,比如设置bot、命令和前缀。 我不知道如何让机器人“读取”被检查人所在的服务器。 有什么帮助吗?谢谢

另外,我到目前为止编写的代码如下

import discord
from discord.exr import commands

client = commands.bot(command_prefix = "chk!")


client = discord.Client()

@client.command()
async def check(ctx, member : discord.Member):
    await hereiswhereigotstuck

@client.event
async def on_ready:
    print('Bot Succesfully Started.')
    



client.run('token')

Tags: import命令服务器client权限asyncdefcheck
1条回答
网友
1楼 · 发布于 2024-04-27 01:01:58

“显而易见”的答案是使用Profile.mutual_guilds,但是不允许Bot帐户访问用户配置文件

机器人实现这一点的唯一方法不是非常有效,但您可以使用client.guilds迭代机器人所在的所有公会,然后使用类似Guild.get_member的方法检查用户是否在该公会中

你也可以看到你的用户是否在guild.members,但是如果你的公会规模很大,我不确定这会有多大的效率

相关问题 更多 >