How do I make my command not mention the user? - javascript

I just started coding my Discord bot and I made a command that replies to every message that isn’t sent by a bot. When I tried it in DMs it works fine, but when I tried it in my server it would mention the user before the command. In the DM it would say just “test”, but in the server it would say something like “#ExampleUser, test”.
Is there a way I can fix this? Here’s my code:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on("message", (message) => {
if (message.author.bot) return;
return message.reply("test")
});

Instead of message.reply('test') use message.channel.send('test') that sends a message to the channel the original message was sent to.

Solution
use message.channel.send('string'); instead of .reply()

It's very easy :)
Instead of saying message.reply('message') you just have to say message.channel.send('message')

Related

How to send a message to another Discord server on a specific channel? [duplicate]

I'm failing to achieve something very simple. I can't send a message to a specific channel. I've browsed trough the documentation and similar threads on stack overflow.
client.channels.get().send()
does NOT work.
It is not a function.
I also do not see it as a method on the Channel class on the official documentation yet every thread I've found so far has told me to use that.
I managed to have the bot reply to a message by listening for a message and then using message.reply() but I don't want that. I want my bot to say something in a specific channel in client.on('ready')
What am I missing?
You didn't provide any code that you already tested so I will give you the code for your ready event that will work!
client.on('ready', client => {
client.channels.get('CHANNEL ID').send('Hello here!');
})
Be careful that your channel id a string.
Let me know if it worked, thank you!
2020 Jun 13 Edit:
A Discord.js update requires the cache member of channels before the get method.
If your modules are legacy the above would still work. My recent solution works changing the send line as follows.
client.channels.cache.get('CHANNEL ID').send('Hello here!')
If you are using TypeScript, you will need to cast the channel in order to use the TextChannel.send(message) method without compiler errors.
import { TextChannel } from 'discord.js';
( client.channels.cache.get('CHANNEL ID') as TextChannel ).send('Hello here!')
for v12 it would be the following:
client.on('messageCreate', message => {
client.channels.cache.get('CHANNEL ID').send('Hello here!');
})
edit: I changed it to log a message.
This will work for the newest version of node.js msg.guild.channels.cache.find(i => i.name === 'announcements').send(annEmbed)
This should work
client.channels.fetch('CHANNEL_ID')
.then(channel=>channel.send('booyah!'))
Here's how I send a message to a specific channel every time a message is deleted. This is helpful if you'd like to send the message without a channel ID.
client.on("messageDelete", (messageDelete) => {
const channel = messageDelete.guild.channels.find(ch => ch.name === 'channel name here');
channel.send(`The message : "${messageDelete.content}" by ${messageDelete.author} was deleted. Their ID is ${messageDelete.author.id}`);
});
Make sure to define it if you're not using messageDelete.

Kickme Discord.js command

Im trying to make a command that allows any user to !kickme which will obviously kick them. I would also like the command to send them a dm, im having issues getting started on the kickme part of it, i also cant quite figure out how to get it to dm the specific person that initiated the command, could someone point me in the right way? Below is my current code, although im not sure what good it will do
const Discord = require('discord.js')
module.exports.run = async (bot, message, args) => {
const member = message.guild.member(user);
message.member
}
}
module.exports.help = {
name: "kickme"
}
To message a user you would do this:
message.author.send("you have been kicked")
I would send this before kicking the user to simplify the coding process :)
also please ask for help on errors, trying using the docs or existing threads first

Bot is not defined or Client.channel.get is not a funtion... Why?

I have a little problem. I want to create an announcement command for my Discord bot. I found a "reffer code" in a topic but when I use it, the debug console send me "bot is not defined" or when I replace bot by Client "Client.channels.get" is not a function.. Can you explain me what is wrong?
const msg = message.content;
const announceChannel = bot.channels.get("778027412435763233");
if (cmd === '${prefix}announce') {
let announceEmbed = new Discord.RichEmbed()
.setTitle(":flag_jp: **Annonce** :flag_jp:")
.setDescription(msg)
.setColor("#ff0000");
return announceChannel.send(announceEmbed);
}
First of all, please provide the code in text next time you're trying to get support on here, it's a lot better for us when trying to provide support.
With v12 coming along, the channel objects you're getting must be cached, and it can simply be done using the function:
bot.channels.cache.get('channel id here');
In your example you are using Client.login, so I have to assume that Client is your bot. Then you can simply do:
let announceChannel = Client.channels.cache.get('Channel ID Here');
You are using RichEmbed as well, which means wether you are using an outdated version of discord.js or you don't know that it is MessageEmbed in discord.js v12. Type npm i discord.js#latest in your terminal (or whereever you install packages for your bot). Then replace RichEmbed() with MessageEmbed() and use my first example for the channel.

Is there a way for a Javascript Discord Bot to send a DM to a specific person?

I am trying to create a system that allows a user to send a message and receive a DM from a bot. That part is working fine. However, I also want the bot to send a message to myself when that happens. Whenever I try to get it to send a message to me, it will always have an error.
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', message => {
if (message.toString().toLowerCase().includes('support')) {
message.author.send('Your assistance ticket has been created. Please wait for a DM from ageekdude.')
message.ageekdude.send(message.author + ' has requested an assistance ticket.')
}
});
client.login('token here');
At the part where it says message.ageekdude.send, I'm trying to get it to send that message to me. Also, at the part where it says message.author, could you tell me how to make it say the name of the user instead of the user ID?
if (message.toString().toLowerCase().includes('support')) {
message.author.send('Your assistance ticket has been created. Please wait for a DM from ageekdude.');
const ageekdude = client.users.cache.get('PASTE YOUR USER ID HERE');
if (ageekdude) ageekdude.send(message.author + ' has requested an assistance ticket.')
}
This will try to find you in the list of all bot's users, and then send you the message,
I hope this will solve your issue !

How do I get my discord bot react to it being mentioned?

I'm trying to get my JavaScript Discord bot to react to being mentioned in discord. However, it doesn't do anything when someone mentions it.
const Discord = require('discord.js');
const keepAlive = require('./server');
const client = new Discord.Client();
client.on('message', message => {
if (message.toString().toLowerCase().includes('#class of 2020 assistant')) {
message.author.send('Your assistance ticket haassistancese wait for a DM from ageekdude.');
const ageekdude = client.users.cache.get('571713056673890324');
if (ageekdude) ageekdude.send(`${message.author} has requested an assistance ticket.`)
}
});
keepAlive();
client.login(process.env.TOKEN);
Could someone please give me a suggestion on how I get the bot to react to it being mentioned?
To make your bot react to it being mentionned, this if statement should be enough :
if (/<#!YourBotID>|<#YourBotID>/.test(message.content)) {
return message.reply('hey, you mentioned me !');
}
You'll need to use the ! as well because user mentions are not the same on PC and mobile.
Happy coding ;)

Categories