【问题标题】:How to I make my bot message the response to a command in a specific channel如何让我的机器人消息响应特定频道中的命令
【发布时间】:2022-01-20 23:02:59
【问题描述】:

所以我已经编写了这个可以正常工作的命令,但是我的问题是我似乎无法弄清楚如何让我的机器人在我提供 id 的特定频道中发送对命令的响应:

const allowed_channel_id = guild.channels.cache.get("920766195878228028")

const Discord = require('discord.js')
    const { TextChannel } = require ('discord.js');
    
    module.exports = {
        commands: ['serverinfo'],
        expectedArgs: '',
        permissionError: 'You need admin permissions to run this command',
        minArgs: 0,
        maxArgs: 0,
        callback: (message, arguments, text) => {
        const server_rules_id = '753465151105138858'
        const server_support_id = '812811612830302219'
        const { guild } = message
        const { name, memberCount, afkTimeout } = guild
        const icon = guild.iconURL()
        const allowed_channel_id = guild.channels.cache.get("920766195878228028")
        let afkTimeout_mins = afkTimeout / 60
        const embed = new Discord.MessageEmbed()
        .setColor('DARK_PURPLE')
        .setTitle(`Server info for "${name}"`)
        .setDescription("here's all the server information you need to get you started!")
        .setThumbnail(icon)
        .addFields(
          {
            name: 'Make sure to review our rules:',
            value: `<#${server_rules_id}>`,
          },
          {
            name: 'Owners',
            value: `Lexa & FiatLux`,
          },
          {
            name: 'Support channel:',
            value: `<#${server_support_id}>`,
          },
          {
            name: 'Members',
            value: `${memberCount}`,
          },
          {
            name: 'AFK Timeout:',
            value: `${afkTimeout_mins} mins`,
          }
        )
        .setFooter('we hope you have a great time! ????')
        message.channel.send({ embeds: [embed] })
    },
      permissions: [],
      requiredRoles: [],
    } 

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    尝试使用 const allowed_channel_id = client.channels.cache.get("920766195878228028") 代替。

    【讨论】:

      【解决方案2】:

      所以经过更多的实验后,我让它工作了。您需要做的就是: 在你定义之后

       const allowed_channel_id = "920766195878228028"
      

      你需要输入一个 if 语句。

      if (message.channel.id != allowed_channel_id) {}
      

      如果您基本上询问您当前正在写入的频道的 id 是否等于您允许的频道的 id。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-17
        • 2019-11-23
        • 2021-11-28
        • 1970-01-01
        • 2019-01-31
        • 2021-01-09
        • 2021-07-19
        • 1970-01-01
        相关资源
        最近更新 更多