Javascript 未填充message.member.roles
我的Discord机器人最近停止工作(我怀疑是在我的服务器升级到社区服务器时) 首先,有关守则:Javascript 未填充message.member.roles,javascript,discord.js,Javascript,Discord.js,我的Discord机器人最近停止工作(我怀疑是在我的服务器升级到社区服务器时) 首先,有关守则: const Discord = require("discord.js"); const bot = new Discord.Client(); const auth = require("./auth.json"); // contains bot's auth token const srvRoles = require("./role
const Discord = require("discord.js");
const bot = new Discord.Client();
const auth = require("./auth.json"); // contains bot's auth token
const srvRoles = require("./roles.json"); // Server role names are in here
const config = require("./config.json"); // the bot's command prefix is in here
bot.on("message", async message => {
// ...
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
// ...
if(command === "say") {
// makes the bot say something and delete the command message. Admin & Mod only.
// To get the "message" itself we join the `args` back into a string with spaces:
// Role check:
// if(!message.member.roles.some(r=>[srvRoles.administrator, srvRoles.moderator].includes(r.name)) ) // discord.js v11
if(!message.member.roles.cache.some(r=>[srvRoles.administrator, srvRoles.moderator].includes(r.name)) ) // discord.js v12
return message.reply("Sorry, you don't have permissions to use this command.");
const sayMessage = args.join(" ");
// And we get the bot to say the thing:
message.channel.send(sayMessage).catch(console.error);
// Then we delete the command message.
message.delete().catch(console.error);
} // end "say"
// ...
}
bot.on('error', console.error);
bot.login(auth.token);
这在11版行中运行得很好,但它坏了,所以我升级到12版并更改了行。但无论哪种方式,现在它都会失败,并显示以下消息:
(节点:12208)未处理的PromisejectionWarning:TypeError:无法读取未定义的属性“some”
正在引用message.member.roles.cache
Message.member返回ID,但未定义Message.member.roles和down
我应该去拿点什么吗?还是以不同的方式检查角色
编辑:我已经启用了特权意图。机器人分为两个行会。其中一个托管它使用的表情符号。另一个约有185名成员
有没有一种方法可以让我在client.on(“ready”)上预填充缓存?或者让我按需缓存guildMember?您需要打开开发门户中的intents以获取某些事件和成员缓存。Discord几天前做了一些更改。我打开了两个安全意图并刷新了机器人的身份验证密钥。我需要做更多吗?这两个选项是否位于
Bot
选项卡中的Privileged Gateway Intents
下?是。帮会成员和另一个。状态意图和服务器成员意图它现在工作吗?