亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我的 discord Bot 每次嘗試離線時都不會發送命令

我的 discord Bot 每次嘗試離線時都不會發送命令

狐的傳說 2023-01-06 16:10:23
const Discord = require('discord.js')const Client = new Discord.Client();const {prefix,token} = require('./config.json');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('Ready!');});Client.on('message', message => {      if (!message.content.startsWith(prefix) || message.author.bot) return;  if (!Client.commands.has(command)) return;  const args = message.content.slice(prefix.length).trim().split(/ +/);  const command = args.content().toLowerCase();    try {    Client.commands.get(command).execute(message, args);  } catch (error) {    message.reply('error')  }});我希望有人可以提供幫助,我和我的朋友一直在努力修復錯誤,但我們無法修復它我會將錯誤發送給任何可以提供幫助的人,我和我的朋友在命令中有命令但我知道他們給了我們錯誤。
查看完整描述

1 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

只需if (!Client.commands.has(command)) return;在 的聲明之后移動此行 () command。然后它應該工作得很好。


const Discord = require('discord.js')

const Client = new Discord.Client();

const {prefix,token} = require('./config.json');

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('Ready!');

});


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.content().toLowerCase();


  if (!Client.commands.has(command)) return;

  

  try {

    Client.commands.get(command).execute(message, args);

  } catch (error) {

    message.reply('error')

  }

});


查看完整回答
反對 回復 2023-01-06
  • 1 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號