Before I added the reaction code, it worked fine just as a basic rule. But I wanted to make people have to accept the rules to continue to the discord. Then, I have issues, I think part of the issue is the intents and partials but I need the intents to allow the bot to start and the partials to allow the code to do reactions and channels so the rules bot can access the channel where the role adding/accepting rules will be.
Main.js
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES",]},{partials: ["MESSAGE", "CHANNEL", "REACTION"]});
const prefix = '-';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () =>{
console.log('Roleplay Is Online');
});
client.on('guildMemberAdd', guildMember =>{
let welcomeRole = guildMember.guild.roles.cache.find('973945417991589938');
guildMember.roles.add(welcomeRole);
guildMember.guild.channels.cache.get('974611802941968447').send(`Welcome <@${guildMember.user.id}> to our server! Make sure to check out the rules channel!`)
});
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 === 'rules'){
client.commands.get('rules').execute(message, args, Discord);}else if(command === 'clear'){client.commands.get('clear').execute(message, args, Discord);}else if(command === 'kick'){client.commands.get('kick').execute(message, args, Discord);}else if(command === 'ban'){client.commands.get('ban').execute(message, args, Discord);
}else if(command === 'mute'){client.commands.get('mute').execute(message, args, Discord);};
});
client.login('****************************************');
Rules.js
module.exports = {
name: 'rules',
description: 'rule command',
async execute(message, args, Discord, client){
const channel = '973944809444245504';
const MemberRole = message.guild.roles.cache.find("973945417991589938");
const MemberEmoji = ':ballot_box_with_check:';
let embed = new Discord.MessageEmbed()
.setColor('#e42643')
.setTitle('Rules')
.setDescription('Server Rules You Must Follow')
.addFields(
{ name: 'Rule 1', value: 'Respect Everyone We Are All Human!', inline: false },
{ name: 'Rule 2', value: 'No Explicit Content Will Resault In Instant Ban', inline: false },
{ name: 'Rule 3', value: 'Do Not Spam @ Mods Or Owners You Will be Kicked If Repeat Offence = Ban', inline: false },
{ name: 'Rule 4', value: 'Each Channel Has Its Own Use So Use The Right One Please', inline: false },
{ name: 'Rule 5', value: 'No Trolling/Spamming This Resaults In Kick', inline: false },
{ name: 'Rule 6', value:'Any Exploiting of the Roleplay bot will resault in a character reset please report any bugs or exploits that are found Thanks.'},
{ name: 'Do You Agree', value: 'if you agree to the rules please click the tick below if you do not follow the rules you agree to will consit of punishments.'}
)
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(MemberEmoji);
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 === MemberEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(MemberRole);
}
} 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 === MemberEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(MemberRole);
}
} else {
return;
}
});
}
}
The error I'm getting when I run the command -rules
is:
Roleplay Is Online
(node:17556) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
C:\Users\*****\Desktop\TBots\Roleplay\node_modules\@discordjs\collection\dist\index.js:122
if (fn(val, key, this))
^
TypeError: fn is not a function
at Map.find (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\@discordjs\collection\dist\index.js:122:11)
at Object.execute (C:\Users\*****\Desktop\TBots\Roleplay\commands\rules.js:6:54)
at Client.<anonymous> (C:\Users\*****\Desktop\TBots\Roleplay\main.js:31:38)
at Client.emit (node:events:527:28)
at MessageCreateAction.handle (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\actions\MessageCreate.js:34:18)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
at WebSocketShard.onPacket (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\******\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\*******\Desktop\TBots\Roleplay\node_modules\ws\lib\event-target.js:199:18)
PS C:\Users\*******\Desktop\TBots\Roleplay>
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Aj5OMb1
Comments
Post a Comment