javascript - 发送错误命令时,Bot 不断崩溃。[不和谐 JS]
问题描述
我正在尝试制作 Arby 的机器人。每当有人在频道中发送消息时,机器人就会崩溃并且机器人无法工作。
client.on("message", (message) => {
if (message.content.startsWith("arbys") || message.guild.channel == message.guild.channels.cache.get("843008525335920651")) {
} else
setTimeout(() => message.delete(), 1);
message.author.send("**arbys** Only Arbys. GOT IT?")
});
如果有人可以请帮助我,那将是惊人的。
解决方案
message.guild
没有channel
财产,但这不是唯一的问题。您不能像这样将一个对象 ( message.guild.channel
) 与另一个对象 ( message.guild.channels.cache.get("843008525335920651")
) 进行比较。但是,您可以检查发送消息的通道是否具有与您想要的相同的 ID ( 843008525335920651
)。
.then()
您也可以在使用该方法向消息作者发送 DM 后删除该消息。查看下面的代码:
client.on('message', (message) => {
if (
message.content.startsWith('arbys') ||
message.channel.id === '843008525335920651'
) {
// do something ?
console.log('Correct channel or command');
} else {
// send a DM to the author
message.author
.send('**arbys** Only Arbys. GOT IT?')
// and delete the original message
.then(() => message.delete())
// catch them errors :)
.catch((error) => console.log(error));
}
});
推荐阅读
- python - 如何从中心值开始 for-next-loop 到极端
- python - 如何使用多列将宽数据集重塑为长数据集?
- c++ - C++ 如果需要返回,何时删除用 new 初始化的对象?
- reactjs - TypeError:无法读取 ReactJS 中未定义的属性“indexOf”
- rust - 如何在 Rust 中按值传递盒装特征对象?
- javascript - Javascript Promise - 传播和添加其他方法
- reactjs - 如何避免将调度作为道具传递给需要它的组件,但通过 connect() 接收调度?
- java - 如何反序列化仅具有 ID 或对象本身的对象?
- javascript - 在这种情况下如何让 Discord bot 编辑嵌入消息?
- javascript - 按动态列进行角度过滤