【发布时间】:2021-10-28 08:10:49
【问题描述】:
所以这在早些时候工作,但在添加我的 guildCache 地图以保存服务器特定变量后,它停止工作。我不确定错误发生在哪里,所以我将发送我的所有代码,直到错误点。基本上,在我的 guildCreate 事件中,机器人通常会向服务器所有者发送图像和文本,但突然之间,我的工作代码现在被破坏了。有什么想法吗?
我的意图是 GUILDS、GUILD_MESSAGES、DIRECT_MESSAGES
// Require the necessary modules
const config = require('./Data/config.json');
const insulter = require('insult');
require('dotenv').config();
const { Client, Collection } = require('discord.js');
// Create a new client instance
const client = new Client({ intents: 4609 }); // GUILDS, GUILD_MESSAGES, DIRECT_MESSAGES
const guildCache = new Collection(); //For saving independent server variables
// Functions
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
return client.users.cache.get(mention);
}
}
// --------------- BOT EVENTS -----------------
client.once('ready', () => {
console.log(`[Client] Logged in as ${client.user.tag}!`);
client.user.setActivity('you cry.', {
type: 'WATCHING'
});
// Map servers to cache for variables (also done on server join and leave)
client.guilds.cache.forEach(guild => {
guildCache.set(guild.id, {
bullyTarget: undefined,
lastInsultGenerated: undefined
});
});
console.log(guildCache);
console.log('');
});;
// On join server
client.on('guildCreate', async (guild) => {
console.log(`[Client]: Joined \"${guild.name}\"!`);
guildCache.set(guild.id, {
bullyTarget: undefined,
lastInsultGenerated: undefined
});
console.log(guildCache);
console.log('');
await client.users.cache.get(guild.ownerId).send({
content: 'You\'ll ***regret*** adding me.',
files: [{
attachment: 'src/Data/trollge.jpg',
name: 'trollge.jpg'
}]
})
.then(console.log('[Client]: Sent join message to server owner :D\n'))
.catch(console.error);
});
【问题讨论】:
标签: discord discord.js