python - 如何检查作者是否在 x 服务器中具有 x 角色?
问题描述
我正在尝试检查作者是否在 x 服务器上具有 x 角色以便能够使用该命令但无法使其工作。我只能检查 Author 在该服务器中是否具有 x 角色。
想法:如果用户在 x 服务器中具有 x 角色,将能够在任何服务器上使用特殊命令。
role_id = 569712344226201600
author = ctx.message.author
if role_id in [role.id for role in author.roles]:
await ctx.send("message")
解决方案
您可以只获取角色对象。
role = discord.utils.get(ctx.guild.roles, id=role_id_here)
然后只是:
if role in ctx.author.roles:
...
您的机器人必须在这些服务器上。
推荐阅读
- postgresql - 如何为多个服务分配静态 IP,以便它们可以查询 postgres 数据库?
- bash - 带有“查找”的变量的 Bash 命令替换
- docker - 将 docker-compose 中的服务提取到 Dockerfile
- sql-server - Oracle pl sql 等效 SQL Server 应用语句
- javascript - Typescript 导入在编译为 javascript 时缺少 .js 扩展名
- firebase - 在 Firestore 集合中一次获取 1 个文档,不传递任何键或过滤器,仅按它们添加的顺序?
- java - 在 Java 中将对象列表添加到 flink 表的最佳方法是什么?
- python - 外壳排序显示“列表索引超出范围”,我无法弄清楚
- laravel - 启动 Vue.js 变量作为服务器生成的值
- python - 困境试图将此代码与以下代码绑定以制作密码进入程序