【发布时间】:2021-12-21 19:20:24
【问题描述】:
我在使用 DiscordJS v13 向用户添加角色时遇到问题。有什么办法吗?每当我添加它们时,它们都没有定义。这是我要添加添加角色的代码。我是 discord.js 的初学者,所以请耐心等待。谢谢!
} else if (commandName === 'verification'){
let code1 = 'A96B2UUH'
const code = options.getString('code')
if(code === code1){
interaction.reply({
content: 'The code has been accepted. Welcome to the hub!',
ephemeral: true,
})
let role = message.guild.roles.cache.some(role => role.name === 'Equitability')
message.member.roles.add(role)
}else{
interaction.reply({
content: 'You entered the wrong code. Please contact the administrators to gain access.',
ephemeral: true,
})
}
}
})
编辑:我修好了!我改变了一些东西,不知何故它起作用了。这是代码。
bot.on('interactionCreate', async interaction => {
if(!interaction.isCommand()) return
const { options } = interaction
if(interaction.commandName === 'verification'){
let code1 = 'A96B2UUH'
const code = options.getString('code')
if(code === code1){
await interaction.reply({
content: 'You entered the correct code. Welcome to the hub!',
ephemeral: true,
})
var guild = bot.guilds.cache.get('907259574342537236')
const member = await guild.members.fetch(interaction.user.id)
const role = await guild.roles.fetch('907261775622328352')
member.roles.add(role)
}else{
await interaction.reply({
content: 'The code you entered is incorrect. Contact the administrators to gain access the server.',
ephemeral: true,
})
}
}
})
【问题讨论】:
标签: javascript node.js discord discord.js