This is my first time using a command handler and I've been having some trouble adding a command it's not 100% finished so if the code doesn't make sense that's why. When I run the command I get the error listed below, I have no idea what's causing this and I'm really not good with this sort of stuff, any information/tips will help.
ERROR:
TypeError: message.reply is not a function
at Object.execute (C:\Users\lachi\Documents\src\Staniel Native\commands\rps.js:15:21)
at Client.<anonymous> (C:\Users\lachi\Documents\src\Staniel Native\index.js:47:32)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\lachi\Documents\src\Staniel Native\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\lachi\Documents\src\Staniel Native\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\lachi\Documents\src\Staniel Native\node_modules\discord.j at WebSocketShard.onPacket (C:\Users\lachi\Documents\src\Staniel Native\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\lachi\Documents\src\Staniel Native\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\lachi\Documents\src\Staniel Native\node_modules\ws\lib\event-target.js:132:16)
index.js:
//Requirements//
const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const Command_Files = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
require('dotenv').config()
//Bot Settings//
const Prefix = 's!';
const Bot_Name = 'Staniel';
const Bot_Activity = 'over the server!';
const Bot_Activity_Type = {type: 'WATCHING'}; //PLAYING|STREAMING|LISTENING|WATCHING|CUSTOM_STATUS|COMPETING//
//API Keys ETC//
const Discord_Token = process.env.DISCORD_TOKEN;
const YouTube_API = process.env.YOUTUBE_API;
const Twitch_API = process.env.TWITCH_API;
//Server IDs//
const Server_ID = client.guilds.cache.get('854000618367746049');
const Member_Count_Channel = '854375625552560168';
const YouTube_Sub_Count_Channel = '854424982460694529';
const Twitch_Follower_Count_Channel = null;
//On Start//
client.on('ready', () => {
console.log(`${Bot_Name} is now online!`);
});
//Command Handler//
for (const file of Command_Files) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
};
client.on('message', message => {
if (!message.content.startsWith(Prefix) || message.author.bot) return;
const args = message.content.slice(Prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(Prefix, client, message, args);
} catch (error) {
console.error(error);
message.reply('Error executing that command!');
}
});
//Run Bot//
client.login(Discord_Token)
rps.js:
module.exports = {
name: 'rps',
description: 'A simple RPS Minigame!',
execute(Prefix, message, args) {
//Customize Bot//
No_Choice_Reply = `Correct Usage: ${Prefix}rps [rock|paper|scissors]`;
Game_Tie_Reply = "";
//DONT TOUCH//
const Accepted_Replies = ['rock', 'paper', 'scissors'];
const Bot_Algorithm = Math.floor((Math.random() * Accepted_Replies.length));
const Bot_Choice = Accepted_Replies[Bot_Algorithm];
const User_Choice = args[0];
if(!User_Choice) message.reply("Test");
},
};
Thanks, Lachie.
The issue is how you pass to your commands, you are passing "Prefix, client, message, args" but then you have it like this in the command "Prefix, message, args" so you are trying to do client.reply which is not valid.
// Message Event
client.commands.get(command).execute(Prefix, client, message, args);
// Command
// What you have:
execute(Prefix, message, args) {
// What you need:
execute(Prefix, client, message, args) {
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments