[英]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.