簡體   English   中英

discord 機器人不處理命令

[英]discord bot not processing the command

我正在向我的discord v12機器人添加一些新命令。 但它沒有響應我輸入的代碼。 任何幫助表示贊賞。 此部分在 index.js 中

client.admins = new discord.Collection();
const admins = fs.readdirSync('./custom/admin').filter(file => file.endsWith('.js'));
for (const file of admins) {
    const admin = require(`./custom/admin/${file}`);
    client.admins.set(admin.name.toLowerCase(), admin);
};

這是處理以上幾行的代碼

if (message.author.bot || message.channel.type === 'dm') return;

    const prefix = client.config.discord.prefix;

    if (message.content.indexOf(prefix) !== 0) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const admin = args.shift().toLowerCase();

    const adm = client.admins.get(admin) || client.admins.find(adm => adm.aliases && adm.aliases.includes(admin));

    if (adm) adm.execute(client, message, args);

我正在嘗試讓機器人執行的 function 名為 delete.js

module.exports = {
    name: 'snap' ,
    aliases: [],
    category: 'admin',
    utilisation: '{prefix}snap [number]',

    execute(message, args) {
        if(isNaN(args)) return message.reply("Bruh,Specify how much message should I delete")
           if(args>99) return message.reply("You ain't making me do that much work boi")

           if (message.member.hasPermission('ADMINISTRATOR') ){

            const {MessageAttachment} = require('discord.js');
            const snaping = new MessageAttachment('./snap.gif')
            message.channel.send(snaping)
         setTimeout(snapCommand , 9000 ,args, message)  

        }
      else 
      { 
        message.channel.send("-_- you are not an admin,Then why are you trying to use admin commands");
      }
      function snapCommand(args, message){
        var del= args ;
        del = parseInt(del , 10)
       message.channel.bulkDelete(del+2);
      }
    }
    
}

當我啟動機器人時,它沒有顯示任何錯誤消息,所以我認為這是一個好兆頭,但是當我使用.snap 5 '.' 時這是我的前綴。 機器人什么都不做? 控制台也沒有錯誤。 有沒有人有解決這個問題的想法?

沒關系,我通過將客戶端添加到 delete.js 代碼來修復它

execute(client, message, args) {
        if(isNaN(args)) return message.reply("Bruh,Specify how much message should I delete")
           if(args>99) return message.reply("You ain't making me do that much work boi")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM