【发布时间】:2019-11-29 12:01:27
【问题描述】:
我希望我的机器人能够检查...
- 如果我的机器人创建的频道与某个名称匹配... 或
- 如果我的机器人创建的角色与某个名称匹配...
那么
机器人将返回带有消息Mod mail is already activated here!的操作
这是我的代码
var mg = message.guild
const mythings = mg.channels.filter(chane => chane.client.user.id === `595840576386236437` && chane.name === 'modmail' &&chane.type === `text`);
const mythings2 = mg.channels.filter(chane => chane.client.user.id === `595840576386236437` && chane.name === 'qanda' &&chane.type === `text`);
const mythings3 = mg.roles.filter(role => role.client.user.id === `595840576386236437` && role.name === 'ModMail');
console.log(mythings)
if(mythings) return message.channel.send(`Rejected! There's possible fragments of modmail already set up here!`)
if(mythings2) return message.channel.send(`Rejected! There's possible fragments of modmail already set up here!`)
if(!mythings3) return message.channel.send(`Rejected! There's possible fragments of modmail already set up here!`)
注意
我在 discord.js-commando 中这样做,而不是 discord.js 所以这是不在我的 index.js 文件中,所以我唯一的限制是我不能引用客户端变量。目录是 ~/commands/extras/modmail.js/ 而不是 ~/index.js/ 我的意思是我不能从 client 变量开始,因为它会以未定义的形式返回给我,但会允许使用 channel.client 之类的内容,因为它定义了发送消息的频道的创建者。
出了什么问题
这就是问题所在。
- Bot 找不到频道频道
- 机器人返回
或
- Bot 找到频道
- Bot 继续扮演所有渠道和角色。
我希望:机器人可以在公会中搜索满足 client.id AND name 期望的频道,然后返回。此外,Bot 可以在公会中搜索满足所有者(my(指我是 bot))id AND name 的角色,然后也返回。
实际结果是机器人在不应该返回时返回,例如当它应该创建一个通道时,Bot 在它没有找到一个通道时返回。 (不过我删掉了它的代码)
【问题讨论】:
-
"...我唯一的限制是我不能引用客户端变量。"你在代码 sn-p 中使用
client? -
在启动通道/角色的客户端中,而不是客户端在引用
bot.login和机器人在index.js文件中执行的其他操作时。这意味着我不能以client开头,因为它是未定义的,但chane.client不是。
标签: javascript discord.js commando