discord - 如何在 Discord.js 中获取用户询问命令的角色
问题描述
我试图找出命令(whotohelp
)的用户是否具有某些角色('Lab Demonstrator`),但是,我似乎不明白如何获得该角色。
对于我的“interactionCreate”,我目前有以下内容:
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
(interaction.commandName);
//gets username
var username = (interaction.user.username);
//test code
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
在 Python@commands.has_any_role("Lab Demonstrator","lab demonstrator", "staff")
中,我使用如下:
@client.command(pass_context=True)
@commands.has_any_role("Lab Demonstrator","lab demonstrator", "staff","teaching-assistant","lecturers","admin", "Admin")
async def whoToHelp(mesage):
什么是 Javascript 替代方案?
解决方案
您可以Collection.some
用于布尔值和Collection.find
角色对象。
布尔值
const hasRole = interaction.member.roles.cache.some(r => r.name === "the_role_name")
//true if they have it, false if they don't
角色对象
const role = interaction.member.roles.cache.find(r => r.name === "the_role_name")
//the role object if they have it
推荐阅读
- sql-server - MS SQL Server,如何修复 table.column 跨所有应用程序的变化
- winapi - 如果电源重置,如何保护带有 Win32 API 的文件不被损坏?
- string - 将 pandas 列中的列表转换为字符串
- javascript - 基于 JSON 间隔更改页面内容
- c# - 由于 App.config 文件中的错误,SQLite 无法加载数据
- excel - 需要excel公式进行多行列查找
- python - Python kivy(kivymd)如何从MD存储和加载数据
- c# - WPF 打开文件并更新窗口
- airflow - 气流元数据数据库权限
- python-3.x - 在 Python 3 中使用 sys.argv 和 Python 解释器