代码之家  ›  专栏  ›  技术社区  ›  Ryuujo dhara gosai

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

  •  0
  • Ryuujo dhara gosai  · 技术社区  · 5 年前

    所以流程是,我发送 !beep 命令到 #general 频道,然后我想让机器人向发送回复 #announcement-channel 所以,让我们假设我的频道ID是 668*****8********* 。但当我试图找到频道并将其发送到那里时,它会返回错误:

    TypeError:无法读取未定义的属性“send”

    这是我写的代码

    const Discord = require('discord.js');
    const client = new Discord.Client();
    
    module.exports = {
      name: 'beep',
      description: 'Beep!',
      execute(message) {
        const channel = client.channels.get('668*****8*********');
        channel.send('Yahoo');
      }
    };
    

    我在另一个问题的多个答案中尝试了几次,但都没有奏效。从字符串更改为整数也不起作用。我也尝试过 console.log(client.channels.get('668*****8*********')) ,但它什么也不返回。

    0 回复  |  直到 5 年前
        1
  •  3
  •   Cipher    5 年前

    您可以使用以下代码:

    您不能在这里使用客户端参数函数,因为不要传递它。也不可能在每个命令文件中创建客户端。 1个令牌-1个客户端

    const Discord = require('discord.js');
    
    module.exports = {
      name: 'beep',
      description: 'Beep!',
      execute(message) {
          if(message.channel.type === 'dm') return
        const channel = message.guild.channels.get('668*****8*********');
        if(!channel) return
        channel.send('Yahoo');
      }
    };