【发布时间】:2020-10-05 20:35:12
【问题描述】:
所以基本上,我试图让我的代码让我的机器人看到当用户在任何文本频道中键入't!say #channel "message"' 时,机器人将转到指定的频道并说“消息”
const { MessageEmbed } = require('discord.js');
module.exports = {
name: 'say',
aliases: ['bc', 'broadcast'],
description: 'Says your input via the bot',
usage: '<input>',
run: async (bot, message, args) => {
if (!message.member.hasPermission(['MANAGE_MESSAGES'])) {
if (message.mentions.channels.size == 0) {
message.reply('please mention a channel first.');
} else if (!message.member.hasPermission(['MANAGE_MESSAGES'])) {
let targetChannel = message.mentions.channels.first();
// Get the message to print
const args = message.content.split(' ').slice(2);
let saytext = args.join(' ');
targetChannel.send(saytext);
message.delete();
}
}
},
};
当我尝试使用该命令时,我在控制台中收到一条错误消息“TypeError: client.commands.get(...).execute is not a function”
这是我的 index.js 文件中的代码 sn-p,命令提示符说它位于
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(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
有人知道我做错了什么吗?
【问题讨论】:
-
您发布的错误表明问题出在
client.commands.get().execute但是在您发布的代码的 sn-p 中,该行不存在。请更新您的问题以显示发生错误的相关代码段,否则我们无法帮助您
标签: javascript node.js discord.js