Message reaction - javascript

I am trying to get my Discord bot to react to people's messages. For example, if somebody said "welcome", the bot will react to their message, because it has the word welcome, which I would set the keyword too. I understand how to get the bot to reply to messages with a response, but not reactions.

In discord.js you can use something like this:
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("message", message => {
if(message.content === "welcome") {
message.react("😄");
}
}
client.login("YOUR_TOKEN");
This in the Discord.js Docs might be helpful as well.

Related

Bot not responding to message

I'm new to this and have been following a tutorial online but I cannot figure out why the bot will not respond to the message.
Things I have checked:
the tokens match up
bot has proper permissions
not missing any ";" etc etc
Here is the code for reference
const Discord = require('discord.js');
const bot = new Discord.Client({ intents: [Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.DirectMessages] });
const token = <token>;
bot.on('ready' , () =>{
console.log('ts ready gangy :3');
})
bot.on('message', msg=>{
if(msg.content === "hi"){
msg.reply('hi');
}
})
bot.login(token);
The code runs and the bot will appear online as normal but when inputting "hi" and sending it, the bot gives no response.
Add Discord.GatewayIntentBits.MessageContent to your intents and tick Message Content Intent if you didn't tick

Discord bot not on members list but online

I'm trying to start my first discord bot. Installed NodeJS on my PC, started app in discord dev tools, make it bot, got token, selected priviliges, added bot to my server. Actually another bot i already have even sent welcome message saying my new bot joined the server. When i start it using command "node main.js" it says it went online, doesn't give any errors, however my bot isn't showing in members list (neither offline nor online) and it doesn't react to messages with its prefix. Here's my main.js code:
const Discord = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '=';
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'status') {
console.log(command);
message.channel.send('Bot dziala poprawnie.');
}
} );
client.once('ready', () => {
console.log('GuruBot online');
});
client.login('my_token_is_here');```
The bot probably doesn't have access to the text channel. Check the bot's permissions on your server, and check the invite link that you're using to make sure that the bot can view channels and incoming messages.
I'm very late to the question, but hopefully this will help anyone who is searching for this issue.

discord bot help command doesn't do anything

I'm making a discord bot but when I do my help command nothing happens.
The code for my help command is:
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
const Embed = new Discord.RichEmbed()
.setColor("YELLOW")
.setTitle("HardBot - Help")
.setDescription(":tada: Subscribe to our YouTube channel!")
.addField("meme", "youtube",true)
.addField("servers", "ping",true)
.addField("invite",true)
.addField("our prefix is h!",true);
message.channel.send(Embed)
}
module.exports.help = {
name: "help"
}
Make sure to update discord.js by using npm i discord.js#latest in your terminal. Then replace RichEmbed with MessageEmbed.
For all changes in discord.js v12 click here.
Edit:
Make sure you fill every field from an embed with values otherwise it is an invalid form body.

bot keeps repeating

This discord bot keeps repeating what it just said concatenating two strings! Please help!
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = "*";
client.on('message', (message) => {
if (message.content == prefix + 'test') {
message.channel.sendMessage("```User Bot is a way to get more users in your discord server. When you first invite the bot, it will create a channel called #invites. You can put your message in #invites by doing the command *message <message>. Doing this command will make the bot broadcast your message and your invite link so all people with the bot in there #invites channel will get the message.```");
} else if (message.content == prefix + 'setup') {
message.channel.sendMessage("```To setup User Bot, you must join the user bot discord listed here. https://discord.gg/amuzrvr, then in #bots type your message!");
} else if (message.channel.guild.name == 'UserBot' && message.channel.name == 'bots') {
channel(message);
}
});
function channel(message) {
message.channel.sendMessage("***A server! " + message.content + "!***")
}
I found an answer, it was triggering every time the bot spoke cause the conditions were and are the same.
As you have found out, the message event checks every single message inputted into the bot's guilds. To avoid it picking up the bot's messages, you can use
if (msg.author.bot) return;
or something along those lines. :)

Discord Bot Node JS simple error .send

I'm having a weird issue while following this tutorial. Building a JS Discord bot, literally only 33 lines in and its throwing errors about .send being undefined. I've googled around and I can't find anything that has helped get any closer to working this out.
const fs = require("fs");
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
client.login(config.token);
client.on("ready", () => {
client.user.setGame(`on ${client.guilds.size} servers`);
console.log(`Ready to serve on ${client.guilds.size} servers, for ${client.users.size} users.`);
});
client.on("guildMemberAdd", (member) => {
console.log(`New User ${member.user.username} has joined ${member.guild.name}` );
member.guild.defaultChannel.send(`${member.user} has joined this server`);
});
client.on("message", (message) => {
if (!message.content.startsWith(config.prefix) || message.author.bot) return;
if (message.content.startsWith(config.prefix + "ping")) {
message.channel.send("pong!");
} else
if (message.content.startsWith(config.prefix + "foo")) {
message.channel.send("bar!");
}
});
client.on("error", (e) => console.error(e));
client.on("warn", (e) => console.warn(e));
client.on("debug", (e) => console.info(e));
When ran, the console.log works without fuss, but the message to default channel throws the following error in PowerShell
C:\Users\super\Desktop\autoslap\mybot.js:18
member.guild.defaultChannel.send(`${member.user} has joined this server`);
^
TypeError: Cannot read property 'send' of undefined
Any help would be appreciated, getting frustrated over what is probably something so simple.
I know this is a late reply and you might've already figured out how to do this, but I will still explain to those who may need help.
As of 03/08/2017, there is no more Default Channel in guilds on
Discord. The #general default channel can be deleted, and the
guild.defaultChannel property no longer works - From
https://anidiots.guide/frequently-asked-questions.html
If you want an alternative, the code from https://anidiots.guide/frequently-asked-questions.html may do the trick. Just enter the site and scroll down until you see Default Channel!
If your bot has admin perms, its "first writable channel" is the one at the top. It could be any channel, so if their default channel was deleted you can potentially annoy a lot of people.
Hope this helps!
javascript node.js discord discord.js
You would get that error if the default channel of the server has been deleted. Previously, you weren't able to delete the default channel but now you can. To be sure, make a new server and try it there.

Categories

Resources