我的 discord.js 版本是 v13,它沒有發送訊息,也沒有在控制臺中給出錯誤,因此我可以嘗試找出它有什么問題。
代碼本身有超過 4000 行代碼,所以我嘗試將它放在單獨的腳本中,只測驗一個函式(即 ping 函式),但仍然沒有。
如果你問,這async只是我經常使用的主腳本中另一個函式的await一部分。
const Discord = require('discord.js');
const client = new Discord.Client({ intents: [ 'DIRECT_MESSAGES', 'GUILD_MESSAGES' ] });
const config = require("./config.json");
client.on("ready", () => {
console.log(`Main script ready! Currently in ${client.guilds.size} servers!`);
client.user.setActivity("Using a test script");
});
client.on('messageCreate', async message => {
if(message.author.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 (message.channel.type == "dm") return;
if(command === "ping") {
const m = await message.channel.send("Loading...")
m.edit(`Pong! ${m.createdTimestamp - message.createdTimestamp}ms. API ${Math.round(client.ping)}ms`)
}
});
client.login(config.token);
uj5u.com熱心網友回復:
您缺少 Intents.FLAGS.GUILDS。
改變:
const client = new Discord.Client({ intents: [ 'DIRECT_MESSAGES', 'GUILD_MESSAGES' ] });
到
const client = new Discord.Client({ intents: [ 'GUILDS', 'DIRECT_MESSAGES', 'GUILD_MESSAGES' ] });
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/436465.html
