Discord.js发送消息到特定频道

时间:2020-08-16 21:21:03

标签: javascript node.js discord discord.js

我想发出一个轮询命令,但无法将其发送消息到特定频道 这是我的代码:

const { tprefix, pollchannel } = require('../config.json');
const Discord = require('discord.js');
const client = new Discord.Client();

module.exports = {
 name: 'poll',
 description: 'can make polls',
 cooldown: 5,
 usage: '[ask] [emoji1] [emoji 2]',
 aliases: ['createpoll'],
 async execute(message) {
  const channel = message.client.channels.fetch(pollchannel);
  message.channel.send('you have 60 seconds.');

  // await new Promise((resolve) => setTimeout(resolve, 60000));
  channel.client.send(`${tprefix} message`);
  message.channel.send('finished');
 },
};

它应发送一条消息“您有60秒。”,然后等待60秒,然后在轮询通道和当前通道中发送一条消息。频道ID正确,并记录在config.json

1 个答案:

答案 0 :(得分:2)

使用:

const channel = message.client.channels.cache.get(pollchannel)
channel.send('hello')