简体   繁体   English

如何修复错误 ReferenceError: prefix is not defined?

[英]How do i fix the error ReferenceError: prefix is not defined?

My code:我的代码:

const Discord = require('discord.js')
const config = require('./config.json');
const client = new Discord.Client();


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.shift().toLowerCase();
    if (message.content === '>ping') {
        message.channel.send('Pong.');
    } else if (message.content === '>beep') {
        message.channel.send('Boop.');
    } else if (message.content === '>serverinfo') {
        message.channel.send(`Server name: ${message.guild.name}\nTotal members: ${message.guild.memberCount}`);
    } else if (message.content === '>userinfo') {
        message.channel.send(`Your username: ${message.author.username}\nYour id: ${message.author.id}`);
    }
});

client.login('lmao no');

my post is most likely code so this is so i can post it pls pls pls pls pls help i need this bot finished in an hour我的帖子很可能是代码,所以这是我可以发布的请帮助我需要这个机器人在一个小时内完成

To be using prefix checking when message event is fired you need to defined it first.要在触发消息事件时使用前缀检查,您需要先定义它。

example: const prefix = ".";例子: const prefix = ".";

const Discord = require('discord.js')
const config = require('./config.json');
const client = new Discord.Client();
const prefix = ".";

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.shift().toLowerCase();
    if (message.content === '>ping') {
        message.channel.send('Pong.');
    } else if (message.content === '>beep') {
        message.channel.send('Boop.');
    } else if (message.content === '>serverinfo') {
        message.channel.send(`Server name: ${message.guild.name}\nTotal members: ${message.guild.memberCount}`);
    } else if (message.content === '>userinfo') {
        message.channel.send(`Your username: ${message.author.username}\nYour id: ${message.author.id}`);
    }
});

client.login('lmao no');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复我的代码:错误:未捕获的 ReferenceError:未定义帐户? - How do I fix my code :error: Uncaught ReferenceError: account is not defined? 如何修复“未捕获的ReferenceError:未定义FB”? - How do I fix “Uncaught ReferenceError: FB is not defined”? 我如何修复错误 Uncaught ReferenceError: addEvent is not defined - How can i fix the error Uncaught ReferenceError: addEvent is not defined 如何修复“Uncaught ReferenceError: nameCheck is not defined”错误? - How to fix “Uncaught ReferenceError: nameCheck is not defined” error? 如何修复“ Uncaught ReferenceError:未定义firebase”错误? - How to fix “Uncaught ReferenceError: firebase is not defined” error? 如何修复 ReferenceError: myFunction is not defined - How can I fix the ReferenceError: myFunction is not defined 如何修复“未定义 jQuery”错误? - How do I fix "jQuery is not defined" error? 我无法修复此错误:未捕获的 ReferenceError:未定义模块 - I cannot fix this error: Uncaught ReferenceError: module is not defined 我如何解决:ReferenceError:未定义WebAssembly - How do I resolve: ReferenceError: WebAssembly is not defined 我该如何解决这个未捕获的ReferenceError? - how do i fix this Uncaught ReferenceError?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM