我的代碼是:(已編輯)
const channels = [];
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('mainframe')
.setDescription('bot will post to the mainframe for you.')
.addStringOption(option =>
option.setName('post')
.setDescription('What you would like posted.')
.setRequired(true)),
async execute(interaction) {
const post = interaction.options.getString('post');
let response = `"${post}".`;
await interaction.guild.channels.cache.get(channels[getRandomInt(channels.length)]).send({ content: response });
},
};
我希望機器人暫時接受命令并將您發送的內容重新發布到另一個頻道或從頻道 ID 陣列中隨機選擇。
據我了解,根據我在這里看到的另一個答案,這通常不可能以這種直接方式進行。但是,此回應使我認為這樣做的方法是讓機器人將 URL 存盤在集合中,然后將其自行發布到某個定向頻道。
這可能嗎?
uj5u.com熱心網友回復:
對的,這是可能的。您只需要知道特定頻道的 ID、訊息內容、嵌入(如果需要)和機器人需要向該頻道發送訊息的權限。您需要在公會中搜索頻道,然后像其他普通訊息一樣將訊息發送到頻道:
interaction.guild.channels.cache.get('channelId').send({ content: 'your message' });
如果您還有其他問題,請評論我的回復。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/518331.html
