Javascript 等待消息,按给定ID获取通道
因此,我希望我的poll命令在对话中询问频道和问题,但我还没有弄清楚当用户只提供ID时如何获得频道,我已经弄清楚我必须使用.content,但我仍然不知道如何实现它 我的代码:Javascript 等待消息,按给定ID获取通道,javascript,async-await,bots,discord,discord.js,Javascript,Async Await,Bots,Discord,Discord.js,因此,我希望我的poll命令在对话中询问频道和问题,但我还没有弄清楚当用户只提供ID时如何获得频道,我已经弄清楚我必须使用.content,但我仍然不知道如何实现它 我的代码: run: async(message, client, args) => { // Channel where the poll should take palce await message.channel.send(`Please provide a channel where the poll sh
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("You need the content to grab the id, but I assume that's already handled by the code that generates the args
parameter.
To get the guild you can use Message.guild
, and then just Guild.channels.cache.get()
That means that your code would look like this:
const channel = response1.first().mentions.channels.first()
|| response1.first().guild.channels.cache.get(args[0]) // Assuming args[0] is your id
run:async(消息、客户端、参数)=>{
//投票应在哪里进行的渠道
wait message.channel.send(`请提供一个应进行轮询的频道,或使用“取消”!`取消此命令)
const response1=await message.channel.awaitMessages(m=>m.author.id===message.author.id,{max:1});
const channel=response1.first()
如果(!通道){
return message.channel.send(`您没有提到或提供应该进行轮询的频道的ID!`)
}
//投票应在哪里进行的渠道
wait message.channel.send(`请为投票提供问题!`)
const response2=await message.channel.awaitMessages(m=>m.author.id===message.author.id,{max:1});
让问题=回答2.first();
如果(!问题){
返回message.channel.send(`您没有指定您的问题!`)
}
const Embed=new Discord.MessageEmbed()
.setTitle(`newpoll!`)
.setDescription(`${question}`)
.setFooter(`${message.author.username}创建了此轮询。`)
.setColor(`0x0099ff`)
让msg=wait client.channels.cache.get(channel.id).send(Embed)
wait msg.react(“您需要内容来获取id,但我假设生成args
参数的代码已经处理了该内容。
要获取公会,您可以使用Message.guild
,然后只需guild.channels.cache.get()
这意味着您的代码如下所示:
const channel=response1.first().提到.channels.first()
||response1.first().guild.channels.cache.get(args[0])//假设args[0]是您的id
所以我用另一个构造函数来解决这个问题,这意味着:
const ID=client.channels.cache.get(response1.first().content)
const channel=response1.first().提及.channels.first()| ID
它现在可以正常工作了谢谢,但是“频道”没有这样定义,这就是错误所说的,是的,内容是由args处理的,我忘记了有人推荐的response1.first().guild.channels.cache.get(),但是它会转到if(!channel)我更新了答案(我忘记添加.first())
afterresponse1
。关于您的问题:请注意,这不仅仅是。get()
,而且您需要传入id().get(args[0]
)我现在有了它,它很像您的评论(通过编辑),但它仍然不接受id(我确定这是一个真实的频道id),并直接转到if(!频道),真让我恼火…您应该尝试进行一些调试,以确保正确拾取参数…尝试使用console.log
查看response1
、args[0]
以及用于频道的两条语句是否正确。