【问题标题】:Discord Bot Auto Deletes Https Links In certain ChannelsDiscord Bot 自动删除某些频道中的 Https 链接
【发布时间】:2021-02-26 22:02:58
【问题描述】:

因此,此代码旨在删除包含https 的任何消息。所以这针对不和谐的链接。但是,我想允许 4 个频道中的链接(频道 ID 如下)。但这目前只是删除所有 https 链接,无论服务器如何——我做错了什么?还是错过了?

if (message.content.includes("https")){
    var channelID = ["766716351007686697", "770229235788677161", "766720626471206942", "766720685723746314"]
    if (message.channel.id === channelID) return;

    const https = new Discord.MessageEmbed()
    https.setTitle(`Deleted Message`)
    https.setDescription("Sorry But We Do Not Allow Links In That Channel");
    https.setTimestamp();

    message.author.send(https);

    message.delete()

没有错误信息出现

【问题讨论】:

  • 你能把它放在try{} catch(err){} 和console.log(err) 中吗?它说什么?
  • @JonahG 如果我将来使用它,我会在代码中的哪个位置添加它?

标签: javascript discord discord.js


【解决方案1】:

message.channel.id === channelID 总是返回 false,因为 channelID 是一个数组,message.channel.id 是一个字符串,它们永远不会匹配。您正在检查 message.channel.id 是否存在于 channelID 数组中,因此用于此的正确代码是:

if (channelID.includes(message.channel.id)) return;

检查message.channel.id 是否在channelID 数组中。

【讨论】:

  • 啊好吧,我不知道。也为解释喝彩
猜你喜欢
  • 2020-11-28
  • 2020-07-13
  • 2019-05-17
  • 2020-10-01
  • 2020-12-04
  • 1970-01-01
  • 2021-06-30
  • 2014-01-30
  • 2021-09-08
相关资源
最近更新 更多