【发布时间】:2021-06-27 00:58:49
【问题描述】:
在 main.js 中(不是那里的所有内容,但有什么问题):
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
client.commands.get('ping').execute(message, args);
} else if (command == 'hello'){
client.commands.get('hello').execute(message, args);
} else if (command == 'command'){
client.commands.get('command').execute(message, args, Discord);
} else if (command == 'clear'){
client.commands.get('clear').execute(message, args);
} else if (command == 'kick'){
client.commands.get('kick').execute(message, args);
} else if (command == 'ban'){
client.commands.get('ban').execute(message, args);
} else if (command == 'mute'){
client.commands.get('mute').execute(message,args);
} else if (command == 'wake'){
client.commands.get('wake up').execute(message,args);
} else if (command == 'play'){
client.commands.get('play').execute(message, args);
} else if (command == 'leave'){
client.commands.get('leave').execute(message, args);
} else if (command == 'coin'){
client.commands.get('coin').execute(message, args, Discord);
} else if (command == 'avatar'){
client.commands.get('avatar').execute(client, message, args);
} else if (command == 'weather'){
client.commands.get('weather').execute(client, message, args);
} else if (command == 'slowmode'){
client.commands.get('slowmode').execute(message, args);
} else if (command == 'youtube'){
client.commands.get('youtube').execute(message, args);
} else if (command == 'kill'){
client.commands.get('kill').execute(message, args);
} else if (command == 'beep'){
client.commands.get('beep').execute(message, args, Discord);
} else if (command == 'spam'){
client.commands.get('spam').execute(message, args, Discord);
} else if (command == 'reactionrole'){
client.commands.get('reactionrole').execute(message, args, Discord);
}
});
reactionrole.js 中的内容:
module.exports = {
name: 'reactionrole',
description: "Sets up a reaction role message!",
async execute(message, args, Discord, client) {
const channel = '????│announcements';
const yellowTeamRole = message.guild.roles.cache.find(role => role.name === "New Role");
const pepepog = 'pepepog';
let embed = new Discord.MessageEmbed()
.setColor('#e42643')
.setTitle('Want A Custom Role?')
.setDescription('Want Your own Custom Role? Yea, Thought So React In The Next 30 Minutes To Get Your Own Custom Role! @dioZ Will Make It When He Is Not Busy!!'
+ `${pepepog} for custom role :))`);
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(pepepog);
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === pepepog) {
await reaction.message.guild.members.cache.get(user.id).roles.add(yellowTeamRole);
}
} else {
return;
}
});
client.on('messageReactionRemove', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === pepepog) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(yellowTeamRole); }
} else {
return;
}
});
}
}
【问题讨论】:
-
client.commands.get('reactionrole')返回未定义。此外,对于未来的问题,请完全格式化您的代码,并且只包含与您所询问的内容相关的行。 -
您可能想向我们展示您收到的错误并格式化您的代码^^
标签: javascript node.js discord.js