【发布时间】:2020-10-31 21:18:11
【问题描述】:
我正在尝试制作一个机器人,当有人键入 !joinchoiceOutOfVariousRoles 时,它会在服务器中添加一个角色。我目前正在使用 discord 版本 12。我的错误消息是:
fn = fn.bind(thisArg);
虽然尝试了各种技术,但我无法让代码工作。
const Discord = require('discord.js');
const client= new Discord.Client();
const token = process.env.DISCORD_BOT_SECRET
client.on('ready', () => {
console.log("I'm in");
console.log(client.user.username);
});
client.on('message', msg => {
if (msg.content.toLowerCase().startsWith("!join"))
{
var args = msg.content.toLowerCase().split(" ")
console.log(args)
if (args[1] === 'sullen')
{
msg.channel.send('You have successfully joined Sullen!')
const sullenRole = msg.guild.roles.cache.find('name','Sullen')
msg.member.addRole(role.id)
}
}
});
client.login(token)
**编辑:修复了每个人都在说的问题,我现在需要做的就是更新权限,(我的朋友必须这样做,因为它不是我的机器人),我应该一切都好。谢谢大家! :D
【问题讨论】:
-
你的代码的第一个问题是你是mixing v11 and v12 code
-
请详细说明一下?
-
您只能在 v12 中使用
cache,而addRole是 v11 语法。你有什么版本? -
现在我使用的是 12.4.1 版本。
-
另外,您对
Collection.prototype.find()使用了错误的语法。请检查我链接的页面。
标签: discord discord.js