Ad
Await Messages, Get A Channel By The Given ID
So i want that my poll command asks for the channel and the question in a conversation, but i haven't figured out how to get the channel when the user only gives the ID, i have figured out that i have to use .content but i still don't know how to implement it.
My code:
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("👎")
}
And it is this line: response1.content.guild.channels.cache.get()
that is writte wrong by me but idk what i have to change/where to add the .content so that it works.
Would be nice if someone can help me.
My message event for the 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!');
}
}
}
Ad
Answer
So i went around it with making another constructor means:
const ID = client.channels.cache.get(response1.first().content) const channel = response1.first().mentions.channels.first() || ID
It works fine now
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad