最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

角色独占命令不起作用 Discord.js

运维笔记admin12浏览0评论

角色独占命令不起作用// Discord.js

角色独占命令不起作用// Discord.js

我的代码目前是:

if (message.content == ",test") {
    if (message.member.roles.find("name", "images")) {        
        message.channel.send( {
            file: ".jpg" // Or replace with FileOptions object
        });
    }
    if (!message.member.roles.find("name", "images")) { // This checks to see if they DONT have it, the "!" inverts the true/false
    message.reply('You need the \`images\` role to use this command.')
    .then(msg => {
      msg.delete(5000)
    })
    }
    message.delete(100); //Supposed to delete message
    return; // this returns the code, so the rest doesn't run. 
}

如果用户具有“图像”角色,我希望机器人在他们说“,测试”时发送图像,并且我希望在几秒钟后删除用户的“,测试”消息。但是,这似乎不起作用。

我试图发送没有角色检查的图像,这是有效的。

我怎样才能解决这个问题?

回答如下:

这是因为message.member.roles.find("name", "images")检查公会中的角色是否存在。为了找出某人是否有角色,你可以使用message.member.roles.has(myRole)。要动态查找角色的ID,您可以使用:let myRole = message.guild.roles.find("name", "Moderators").id;

发布评论

评论列表(0)

  1. 暂无评论