为什么我无法使用令牌登录机器人?



我正在尝试登录我的不和谐机器人,但它只能使用discord.js v12. 我也有一个配置文件,我存储我的令牌,所以我可以使用config.token,但它显示无效.

当我使用v13时,没有工作。即使我使用实际的令牌,它也显示无效当我使用config.token时,它也显示无效。下面是代码:

console.clear();

const Discord = require("discord.js");
const config = require("./Data/config.json");   
const intents = new Discord.Intents(32767);  
const client = new Discord.Client({ intents });

client.on("ready", () => console.log("Bot is online!"));

client.on("messageCreate", message => {
if(message.content == "hello") message.reply("Hello!");

});

client.login("token");

机器人也不回复。这是我的配置文件。

{
"token": "token",
"prefix": "!"
}

您正在尝试使用字符串登录,使用配置中的令牌变量,使用client.login(config.token),周围没有引号。这将获得config变量,然后是其中的token变量或config.token

你的代码看起来像这样:

console.clear();

const Discord = require("discord.js");
const config = require("./Data/config.json");   
const intents = new Discord.Intents(32767);  
const client = new Discord.Client({ intents });

client.on("ready", () => console.log("Bot is online!"));

client.on("messageCreate", message => {
if(message.content == "hello") message.reply("Hello!");

});

client.login(config.token);

最新更新