[英]How can I send a message to a specific channel by using my own "say" command in discord.js?
[英]How can I send a message to a channel inside a command?
我正在嘗試向 config.LOG_CHANNEL 中的通道 ID 發送一條消息
module.exports = {
name: 'ping',
description: 'This is a ping command!',
execute(message, args) {
message.channel.send('Pong');
const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client();
let config = JSON.parse(fs.readFileSync("./config.json"));
const channel = client.channels.cache.get(config.LOG_CHANNEL);
console.log(channel);
console.log(client.channels.cache);
}
}
這是我的控制台輸出:
undefined
Collection [Map] {}
頻道ID是雪花ID嗎? 如果它仍然有 # 或 <> 符號,它將無法訪問您的頻道。 前任。
var channelID = config.LOG_CHANNEL.replace(/<|#|>/g, "") //strip snowflake id to reference channel directly
var channel1 = message.guild.channels.cache.get(channelID)
似乎頻道沒有被緩存。 嘗試使用這個:
client.channels.fetch(config.LOG_CHANNEL);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.