簡體   English   中英

當我對此進行更改時,我的 discord.js 機器人沒有響應,我還是新手,但我看不出有什么問題

[英]My discord.js bot is not responding when i made changes to this, i am still new, but i cant see whats wrong

這是代碼,

const Discord = require('discord.js')
const Keyv = require('keyv');
const client = new Discord.Client()
const prefixes = new Keyv();
const prefix = '/';
const eris = require('eris')

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`)
})

client.on('message',async message => {
    if (message.author.bot) return;

    let args;
    // handle messages in a guild
    if (message.guild) {
        let prefix;

        // if we found a prefix, setup args; otherwise, this isn't a command
        if (!prefix) return;
        args = message.content.slice(prefix.length).split(/ +/);
    } else {
        // handle DMs
        const slice = message.content.startsWith(prefix) ? prefix.length : 0;
        args = message.content.slice(slice).split(/ +/);
    }

    // get the first space-delimited argument after the prefix as the command
    const command = args.shift().toLowerCase();
    if (command === 'args-info') {
        if (!args.length) {
            return message.channel.send(`You didn't provide any arguments, ${message.author}!`);
        }

        message.channel.send(`Command name: ${command}\nArguments: ${args}`);
    }
  
    if (command === 'ping') {
        return message.channel.send('Pong!')
    }
    if ( command === 'help'){
        return message.channel.send('Sorry! I have no commands yet. You can use /ping to make me reply "Pong!"')
    }
    if(message === '(╯°□°)╯︵ ┻━┻'){
        return message.channel.send('(╯°□°)╯︵ ┻━┻ yo face.')  
    }
    if(message === '┬─┬ ノ( ゜-゜ノ)') return message.reply('thanks for returning the table.')
  
    if(command === 'about') return message.channel.send('Creator: mudkip989, Version: 1.0.0, Name: ' +  client.user.tag)
})

client.login(process.env.TOKEN)

我已經測試並且機器人在線,並且我使用了更簡單的代碼,但是當我有這個時,它就不起作用了。 我不明白為什么。 我已經進行了更改,也許我需要了解更多“規則”或 discord 機器人代碼不起作用的東西。

if (message.guild) {
        let prefix;

        // if we found a prefix, setup args; otherwise, this isn't a command
        if (!prefix) return;

看起來您在這里所做的只是聲明一個名為prefix的變量,然后檢查其值是否為假。 這將始終評估為 true,因為prefix的值是未定義的。

指出您的let prefix; 正在用相同的名稱隱藏您的全局常量。

暫無
暫無

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

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