discord.js没有发送到自定义渠道

正式尼克

我做了一个允许用户设置审核通道的命令。set channel命令可以正常工作并将公会ID和通道ID发送到JSON文件中,如下所示:

{"781631298749726730":{"channel":"781719843770466355"}}

但是在我的unban命令中,我似乎无法使它发送到moderationChannel.json它只返回以下文件的内部通道

modChannel.send is not a function

这是unban.js文件中的代码

let channels = JSON.parse(fs.readFileSync("././database/moderationChannel.json", "utf8"))
  
  let modChannel = channels[message.guild.id].channel;

    if(isNaN(args[0])) return message.channel.send(`${switchc} You need to provide an ID.`)
    let bannedMember = await bot.user.fetch(args[0]) || message.guild.members.cache.get(args[0])
        if(!bannedMember) return message.channel.send(`${switchc} Please provide a user id to unban someone!`)

    let reason = args.slice(1).join(" ")
        if(!reason) reason = `${switchc} No reason given!`

    if(!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send(`${switchc} I dont have permission to perform this command!`)|
    message.delete()
    try {
        message.guild.members.unban(bannedMember, reason)
        const bEmbed = new MessageEmbed()
.setColor("RANDOM")
.setDescription(`**${bannedMember.tag}** has been unbanned!`)

    message.channel.send(bEmbed)
    } catch(e) {
        console.log(e.message)
    }
let mEmbed = new MessageEmbed()
  .setTitle(`Member Unbanned`)
  .setDescription("I WORK!")
  modChannel.send(mEmbed)
    }
}

我使用了我的prefix命令中通道的代码,在其中您为行会设置了前缀。我不知道为什么在某个公会的频道集中发送消息不起作用。

如果您需要在我们设置频道的代码,则下面的代码。

  let channels = JSON.parse(fs.readFileSync("././database/moderationChannel.json"));
  
  channels[message.guild.id] = {
    channel: message.channel.id
  }
  
  fs.writeFile("././database/moderationChannel.json", JSON.stringify(channels), (err) => {
    if(err) console.log(err)
  });
  
  let sEmbed = new MessageEmbed()
  
  .setColor(aqua)
  .setTitle(`${message.guild.name} Channel Set`)
  .setDescription(`Set to ${message.channel.name}`);
  message.channel.send(sEmbed);
  }
}
Zsolt Meszaros

问题在于,这modChannelmessage.channel.id一个简单的字符串,即通道的ID,而不是具有send()方法的通道

您可以替换let modChannel = channels[message.guild.id].channel为:

let channelId = channels[message.guild.id].channel;
let modChannel = client.channels.cache.get(channelId);

if (!modChannel) {
  return console.log(`No moderation channel found with ID ${channelId}`);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

discord.js没有发送到自定义渠道

来自分类Dev

Pyhton Discord Bot发送到多个渠道的问题

来自分类Dev

discord.js将消息发送到特定频道

来自分类Dev

discord.js 12有什么方法可以将数据从json文件发送到通道?

来自分类Dev

有没有办法从discord.py获取自定义状态消息?

来自分类Dev

Discord自定义活动属性错误,表情符号对象没有属性“获取”

来自分类Dev

尝试使用Discord.js使用Discord机器人将消息发送到特定频道

来自分类Dev

将嵌入发送到discord.js中的频道不起作用

来自分类Dev

在Discord.js v12 +上将消息发送到其他分片

来自分类Dev

Discord.js V12将数据从json文件发送到单个消息中

来自分类Dev

Discord Py将消息发送到特定频道

来自分类Dev

python-discord.py发送到许多消息

来自分类Dev

Discord意图discord.js

来自分类Dev

Discord.py自定义状态

来自分类Dev

Discord.py自定义状态

来自分类Dev

Discord-仅将消息从python应用发送到Discord通道(单向通信)

来自分类Dev

如何将不和谐消息发送到另一个频道?(Discord JS)

来自分类Dev

Discord.js V12将嵌入内容发送到其他公会中的频道

来自分类Dev

JS Discord Bot 没有反应

来自分类Dev

使用 Discord.js 进行 Discord Markdown

来自分类Dev

自定义Spring Security的LockedException以将新的状态代码发送到angular.js

来自分类Dev

将变量从伏特发送到自定义功能

来自分类Dev

将范围发送到自定义函数

来自分类Dev

将自定义数据发送到Prometheus

来自分类Dev

将DM发送到自定义ID用户

来自分类Dev

将自定义指标发送到谷歌分析

来自分类Dev

有没有一种方法可以将自定义参数发送到rsync服务器?

来自分类Dev

有没有办法将文件发送到 Node-Red 中的自定义节点表单?

来自分类Dev

Discord Python重写-帮助命令错误(自定义)

Related 相关文章

  1. 1

    discord.js没有发送到自定义渠道

  2. 2

    Pyhton Discord Bot发送到多个渠道的问题

  3. 3

    discord.js将消息发送到特定频道

  4. 4

    discord.js 12有什么方法可以将数据从json文件发送到通道?

  5. 5

    有没有办法从discord.py获取自定义状态消息?

  6. 6

    Discord自定义活动属性错误,表情符号对象没有属性“获取”

  7. 7

    尝试使用Discord.js使用Discord机器人将消息发送到特定频道

  8. 8

    将嵌入发送到discord.js中的频道不起作用

  9. 9

    在Discord.js v12 +上将消息发送到其他分片

  10. 10

    Discord.js V12将数据从json文件发送到单个消息中

  11. 11

    Discord Py将消息发送到特定频道

  12. 12

    python-discord.py发送到许多消息

  13. 13

    Discord意图discord.js

  14. 14

    Discord.py自定义状态

  15. 15

    Discord.py自定义状态

  16. 16

    Discord-仅将消息从python应用发送到Discord通道(单向通信)

  17. 17

    如何将不和谐消息发送到另一个频道?(Discord JS)

  18. 18

    Discord.js V12将嵌入内容发送到其他公会中的频道

  19. 19

    JS Discord Bot 没有反应

  20. 20

    使用 Discord.js 进行 Discord Markdown

  21. 21

    自定义Spring Security的LockedException以将新的状态代码发送到angular.js

  22. 22

    将变量从伏特发送到自定义功能

  23. 23

    将范围发送到自定义函数

  24. 24

    将自定义数据发送到Prometheus

  25. 25

    将DM发送到自定义ID用户

  26. 26

    将自定义指标发送到谷歌分析

  27. 27

    有没有一种方法可以将自定义参数发送到rsync服务器?

  28. 28

    有没有办法将文件发送到 Node-Red 中的自定义节点表单?

  29. 29

    Discord Python重写-帮助命令错误(自定义)

热门标签

归档