discord.js - TypeError:message.reply 不是函数
问题描述
这是我第一次使用命令处理程序,我在添加命令时遇到了一些麻烦,它没有 100% 完成,所以如果代码没有意义,那就是原因。当我运行命令时,我得到下面列出的错误,我不知道是什么原因造成的,而且我真的不擅长这种东西,任何信息/提示都会有所帮助。
错误:
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");
},
};
谢谢,拉奇。
解决方案
问题是你如何传递给你的命令,你传递的是“前缀,客户端,消息,参数”,但是你在命令“前缀,消息,参数”中有这样的东西,所以你正在尝试做 client.reply 这是无效。
// 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) {
推荐阅读
- php - 如果有可用描述,如何仅显示类别描述和标题?
- android - NestedScrollview 不适用于 Drawerlayout
- tensorflow - 如何从训练有素的 keras 模型中找到等效的 ONNX 运算符?
- vba - VBA中的索引匹配匹配/vlookup
- jmeter - 如何在 JMeter 中执行线程以完全填充以下场景?
- javascript - Electron.js:如何为一个窗口创建一个单独的下载 webContents.session?
- sql-server - 从哪里获得 Sql server 2019 32 位
- typescript - Angular 12 Chart.js - 无法显示甜甜圈
- postman - Postman - 从 NodeJS 运行的 Newman
- php - 如何在 PHP 的类构造函数中将数组作为参数传递