gpt4 book ai didi

javascript - 等待消息,通过给定的 ID 获取 channel

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

所以我希望我的 poll 命令在对话中询问 channel 和问题,但我还没有想出当用户只提供 ID 时如何获取 channel ,我已经发现我必须使用 .content 但是我仍然不知道如何实现它。

我的代码:

run: async(message, client, args) => {

// Channel where the poll should take palce
await message.channel.send(`Please provide a channel where the poll should take place or cancel this command with "cancel"!`)
const response1 = await message.channel.awaitMessages(m => m.author.id === message.author.id, {max: 1});
const channel = response1.first().mentions.channels.first() || response1.content.guild.channels.cache.get()

if (!channel) {
return message.channel.send(`You did not mention or provide the ID of a channel where the poll should take place!`)
}

// Channel where the poll should take palce
await message.channel.send(`Please provide a question for the poll!`)
const response2 = await message.channel.awaitMessages(m => m.author.id === message.author.id, {max: 1});
let question = response2.first();

if (!question) {
return message.channel.send(`You did not specify your question!`)
}

const Embed = new Discord.MessageEmbed()
.setTitle(`New poll!`)
.setDescription(`${question}`)
.setFooter(`${message.author.username} created this poll.`)
.setColor(`0x0099ff`)
let msg = await client.channels.cache.get(channel.id).send(Embed)
await msg.react("👍")
await msg.react("👎")
}

这是这一行: response1.content.guild.channels.cache.get()我写错了,但我知道我必须更改什么/在哪里添加 .content 以便它工作。

如果有人可以帮助我就好了。

我的 args 消息事件:
module.exports = async (client, message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
if (!message.guild) return;
if (!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(prefix.length).split(/ +/g);
const cmd = args.shift().toLowerCase();
if (cmd.length == 0) return;
let command = client.commands.get(cmd)
if (!command) command = client.commands.get(client.aliases.get(cmd));
if (command) {
try {
command.run(message, client, args)
} catch (error) {
console.error(error);
message.reply('There was an error trying to execute that command!');
}
}
}

最佳答案

您需要获取 id 的内容,但我认为这已经由生成 args 的代码处理了。范围。
要获得公会,您可以使用 Message.guild ,然后只是 Guild.channels.cache.get()
这意味着您的代码将如下所示:

const channel = response1.first().mentions.channels.first() 
|| response1.first().guild.channels.cache.get(args[0]) // Assuming args[0] is your id

关于javascript - 等待消息,通过给定的 ID 获取 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61970298/

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