我的問題是什么?
有時我沒有得到guildCreate和guildDelete事件。
問題是不是每次都出現? 不會。大約 40% 的時間它可以正常作業。
我會收到錯誤訊息嗎?不會。不會觸發任何錯誤訊息。
我的代碼:
const DiscordServer = require('./backend-lib/models/DiscordServer');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD ] });
client.once('ready', () => {
console.log('ready');
});
/* It's listening to the event `guildCreate` and then it's creating a new document in the database. */
client.once('guildCreate', async (guild) => {
console.log('create');
});
/* It's listening to the event `guildDelete` and then it's deleting the document in the database. */
client.once('guildDelete', async (guild) => {
console.log('delete', guild.id);
});
/* It's connecting to SQS and listening to it. */
client.once('ready', async () => {
require('./services/helper');
});
client.login(conf.discord.token)
uj5u.com熱心網友回復:
看來您使用的是正確的意圖。但是,您正在使用,它為您的和事件client.once添加了一個一次性偵聽器。第一次觸發事件時,監聽器被移除并觸發回呼函式。隨著偵聽器被洗掉,除非您重新啟動機器人,否則回呼將不會再次運行。guildCreateguildDelete
如果要多次觸發這些事件,可以使用.on()方法:
client.on('guildCreate', async (guild) => {
console.log('create');
});
client.on('guildDelete', async (guild) => {
console.log('delete', guild.id);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/484646.html
上一篇:如何計算帖子的瀏覽量
下一篇:為朋友的帖子制作演算法?
