gpt4 book ai didi

javascript - "ready"事件从未被调用

转载 作者:行者123 更新时间:2023-12-03 01:12:30 25 4
gpt4 key购买 nike

我正在对我的第一个 Discord 机器人进行编程,我将其编程为在启动时(或者换句话说,每当 client.on("ready") 被调用时)向控制台输出一些内容。但是,我无法让它真正点火,我也不知道为什么。我安装了所有节点依赖项,机器人位于服务器中并且能够发送消息,并且程序的前几行运行良好。
有什么问题吗?

来源如下:

console.log("Launching bot...\n");

const Discord = require("discord.js");

const client = new Discord.Client();

const config = require("./config.json");

client.on("ready", () => {
console.log(`Bot has started, with
${client.users.size} users, in
${client.channels.size} channels of
${client.guilds.size} guilds.`);
client.user.setActivity(`Serving
${client.guilds.size} servers`);
});

client.on("message", async message => {
if(message.authot.bot) return;

if(message.content.indexOf(config.prefix) !== 0)
return;

const args =
message.content
.slice(config.prefix.length).trim().split(/ +
/g);
const command = args.shift().toLowerCase();

if(command === "ping") {
let m = await message.channel.send("Ping?");
m.edit(`Pong! Latency is ${m.createdTimestamp -
message.createdTimestamp}ms. API Latency is
${Math.round(client.ping)}ms`);
}
});

最佳答案

您忘记使用.login方法为您的客户端,这就是为什么您的 ready 事件没有被触发的原因!

这是更新后的代码,您只需插入 https://discordapp.com/developers/applications/ 中的绝密 key 即可

console.log("Launching bot...\n");

const Discord = require("discord.js");

const client = new Discord.Client();

const config = require("./config.json");

client.on("ready", () => {
console.log(`Bot has started, with
${client.users.size} users, in
${client.channels.size} channels of
${client.guilds.size} guilds.`);
client.user.setActivity(`Serving
${client.guilds.size} servers`);
});

client.on("message", async message => {
if(message.authot.bot) return;

if(message.content.indexOf(config.prefix) !== 0)
return;

const args =
message.content
.slice(config.prefix.length).trim().split(/ +
/g);
const command = args.shift().toLowerCase();

if(command === "ping") {
let m = await message.channel.send("Ping?");
m.edit(`Pong! Latency is ${m.createdTimestamp -
message.createdTimestamp}ms. API Latency is
${Math.round(client.ping)}ms`);
}
});

client.login("YOUR TOP SECRET KEY")

关于javascript - "ready"事件从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52158131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com