所以基本上,我试图让我的代码让我的机器人看到当用户在任何文本频道中键入“t!say #channel“消息””时,机器人将转到指定的频道并说“消息”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 文件中的代码片段,命令提示符显示它位于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!'); }});有人知道我做错了什么吗?
1 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
根据您更新的问题,我的猜测是该错误是由于您调用.execute()命令而命令没有execute功能引起的。从您的say命令代码来看,您的命令似乎具有.run功能。
所以尝试改变
client.commands.get(command).execute(message, args);
到
// I've added the `client` property because your run command takes three arguments, not two.
client.commands.get(command).run(client, message, args);
添加回答
举报
0/150
提交
取消