Learn to Code via Tutorials on Repl.it!

← Back to all posts
DISCORD.JS poll command
Bruno08432190 (1)

// Load modules
const Discord = require("discord.js"),
backup = require("discord-backup"),
client = new Discord.Client(),

settings = {
prefix: "YOUR-PREFIX",
token: "YOUR-TOKEN"
};
require('http').createServer((req, res) => res.end(Bot online)).listen(3000);

function presence(){
client.user.setPresence({
status:"online",
activity: {
name: "how to make a poll command",
type: "WATCHING"
}
})
}
client.once('ready', () => {
console.log("Ready!");
presence();
});

client.on("message", async message => {

// This reads the first part of your message behind your prefix to see which command you want to use.
let command = message.content.toLowerCase().slice(settings.prefix.length).split(" ")[0];

// These are the arguments behind the commands.
let args = message.content.split(" ").slice(1);

// If the message does not start with your prefix return.
// If the user that types a message is a bot account return.
// If the command comes from DM return.
if (!message.content.startsWith(settings.prefix) || message.author.bot || !message.guild) return;

if(command === "poll"){

let msgArgs = args.join(' ')
if(!msgArgs) return message.channel.send("You need write something").then(message => message.delete({ timeout: 5000 }))
message.delete().catch()
message.channel.send(msgArgs + "?").then(messageReaction => {
messageReaction.react("✅")
messageReaction.react("❎")
})
}
});
client.login(settings.token);