Discord.js bot.login(令牌)有问题。怎么办?
我不熟悉Discord.js中的编码,我有一个问题。向我写入错误是包含bot.login(令牌)的行 你能告诉我我的错误并解释如何改正吗?先谢谢你 向我写入:bot.login(令牌); ^ ReferenceError:未定义bot 反对。(C:\Users\Пззизааааа\Desktop\FNaFRP-bot3.0\index.js:7:1) [90米模块处。_编译(内部/modules/cjs/loader.js:1138:30)[39米 [90米在Object.Module._extensions..js(internal/modules/cjs/loader.js:1158:10)[39米 [Module.load处为90m(内部/modules/cjs/loader.js:986:32)[39m [90米功能模块加载(内部/modules/cjs/loader.js:879:14)[39米 [Function.executeUserEntryPoint[as runMain](internal/modules/run_main.js:71:12)[39m] [90米内部/main/run_main_模块。js:17:47[39米 下面是代码本身Discord.js bot.login(令牌)有问题。怎么办?,discord.js,Discord.js,我不熟悉Discord.js中的编码,我有一个问题。向我写入错误是包含bot.login(令牌)的行 你能告诉我我的错误并解释如何改正吗?先谢谢你 向我写入:bot.login(令牌); ^ ReferenceError:未定义bot 反对。(C:\Users\Пззизааааа\Desktop\FNaFRP-bot3.0\index.js:7:1) [90米模块处。_编译(内部/modules/cjs/loader.js:1138:30)[39米 [90米在Object.Module._ex
const client = new Discord.Client();
const { token } = require ("./config.json")
const prefix = '?'
const noperms = 'I dont think you have premission to do that!'
const norole = 'I dont think you have the right role to do that!'
bot.login(token);
bot.on('reddy', messgae => {
console.log(`${bot.user.username} is succefully on! in ${bot.guilds.size} Servers and in ${bot.channels.size} channels.`)
})
bot.on('message', function(message){
if (message.mentions.users.first() --- bot.user) {
message.channel.send('My prefix is \'?\'')
}
})
bot.on('message', message => {
let args = message.content.substring(prefix.length).split(" ");
switch(args[0]){
case 'help' :
if(!message.member.roles.find(r => r.name === 'Test Role')) return message.channel.send(norole)
message.channels.send('My prefux is \'?\' ').then(msg => {
msg.react('✅')
})
}
})
bot.on('message', message=>{
let args = message.content.substring(prefix.length).split(" ");
switch(args[0]){
case 'clear' :
message.delete();
if(!message.nomber.hasPermission("ADMINISTRATOR")) return message.channel.send(noperms)
if(!args[1]) return message.channel.send('Please provide a number.')
message.channel.bulkDelete(args[1]).then ;{
message.channel.send('- Succefully Deleted').then(msg => {
msg.react("✅")
})
console.log(`${message.author.username} deleted ${args[1]} messages in ${message.channel.name}`)
}
}
})```
您的客户是
client
而不是bot
,您可以更改
const client=new Discord.client();
到const bot=new Discord.client();
或用客户端替换所有bot.
。
编辑:修复了代码中的其他错误
const Discord = require("discord.js");
const bot = new Discord.Client();
const { token } = require ("./config.json")
const prefix = '?'
const noperms = 'I dont think you have premission to do that!'
const norole = 'I dont think you have the right role to do that!'
bot.login(token);
bot.on('ready', () => {
console.log(`${bot.user.username} is succefully on! in ${bot.guilds.cache.size} Servers and in ${bot.channels.cache.size} channels.`)
})
bot.on('message', message => {
if (message.mentions.users.first() == bot.user) {
message.channel.send('My prefix is \'?\'');
}
let args = message.content.substring(prefix.length).split(" ");
switch(args[0]){
case 'help' :
tr = message.member.roles.cache.find(role => role.name === 'Test Role').id;
if(!message.member.roles.cache.has(tr)) return message.channel.send(norole);
return message.channel.send('My prefix is \'?\' ').then(msg => {
msg.react('✅')});
case 'clear' :
message.delete();
if(!message.member.hasPermission("ADMINISTRATOR")) return message.channel.send(noperms)
if(!args[1]) return message.channel.send('Please provide a number.')
message.channel.bulkDelete(args[1]).then ;{
message.channel.send('- Succefully Deleted').then(msg => {
msg.react("✅")
})
console.log(`${message.author.username} deleted ${args[1]} messages in ${message.channel.name}`)
}
}
})
将bot.login(令牌);移动到代码底部
在代码全部关闭之前,您无法登录
const Discord = require("discord.js");
const bot = new Discord.Client();
const { token } = require ("./config.json")
const prefix = '?'
// other code
bot.login(token);
它已启动,但由于某些原因,不响应命令