0
votes

I am trying to make a bot that people can call to make a report vote, if the vote succeeds with there being more than 2 (or X number) more yes than no. It will send a message to a separate channel where only the bot can post and it will send a DM to the server admin (this is what I dont know what to do).

Also I get an error saying:

"const sentEmbed = await msg.channel.send(voting); // Send Embed
                   ^^^^^
SyntaxError: await is only valid in async function"

This is the code I have so far:

if(!msg.mentions.users.first()) return msg.channel.send('You need to mention somebody!'); // Check if no User was Mentioned
const voting = async function new Discord.RichEmbed() // Generate Voting Embed
    .setColor('#42b34d')
    .setFooter('Mute ' + msg.mentions.users.first().tag + ' for 10m?')
    .setImage(msg.mentions.users.first().avatarURL);
const role = msg.guild.roles.find(r => r.name === 'Muted'); // Find Role
if(!role) return msg.channel.send('No Role was found, please make sure you have a muteed role!'); // Make sure there is a Role
const agree = '✅'; // Define Emojis
const disagree = '❌'; // Define Emojis

const sentEmbed = await msg.channel.send(voting); // Send Embed
const filter = (reaction, user) => (reaction.emoji.name === agree || reaction.emoji.name === disagree) && !user.bot; // Filter for Reactions
await sentEmbed.react(agree); // React
await sentEmbed.react(disagree); // React
const voteStatus = await msg.channel.send('Voting started 30 seconds left'); // Send start Message and
const collected = await sentEmbed.awaitReactions(filter, { time: 5000 }); // start Collecting Reactions
const agreed = collected.get(agree) || { count: 1 }; // Retrieve Reactions
const disagreed = collected.get(disagree) || { count : 1 }; // Retrieve Reactions
const agreed_count = agreed.count - 1 ; // Count away Bot Votes
const disagreed_count = disagreed.count - 1; // Count away Bot Votes
voteStatus.edit('Voting endet with: ' + agreed_count + agree + ' and ' + disagreed_count + disagree); // Edit message to show Outcome
if(agreed.count > disagreed.count) {

}
else {
    msg.channel.send('Mute Voting Failed :)');
}

I got this code from another post. And I was trying to adapt it but failed at it. I'm very new at Java.

1
did you try out declaring your function as async?Smakkel

1 Answers

0
votes

The cause of that error is that you're calling await outside of an asynchronous function.

Example of asynchronous function;

async function myFunction() {
    await someOtherFunction();
}