gpt4 book ai didi

javascript - Discord.js 向特定 channel 发送消息

转载 作者:行者123 更新时间:2023-12-04 09:06:13 24 4
gpt4 key购买 nike

我想做一个轮询命令,但我无法让它向特定 channel 发送消息
这是我的代码:

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 秒,然后在轮询 channel 和当前 channel 上发送一条消息。 channel id 是正确的,写在 config.json 中

最佳答案

用:

const channel = message.client.channels.cache.get(pollchannel)
channel.send('hello')
  • ChannelManager Docs
  • Map.prototype.get Method
  • 关于javascript - Discord.js 向特定 channel 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63442047/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com