can my bot reply with a message when pinged only - discord.js

when I ping my discord bot it shows what I made it say, but when someone replies to the bot it still sends the message, I want it to reply only when pinged.

You could add this into your messageCreateevent:
if (message.mentions.has(client.user.id)) return message.channel.send({ content: `My Prefix is ${prefix}` });
You should define your prefix first so it wont get called as undefined and for the bot to show your prefix.
For more information about Discord.js mention: discord.js documentation

Related

Can I catch discord Dyno bot message and auto reply to it?

As title, my scenario is:
Periodically checking if new messages were sent by Dyno bot to specific channel, and reply to it automatically.
Is it possible?
[update1]
Here are some cases:
select the right option based one the message sent by bot
click the right button based one the message sent by bot
[update2]
add some figures. something like these:
Any suggestion is appreciated.
Using discord.py, you can check if a message is written by a bot and reply to it with:
#client.event
async def on_message(self, message): #call the on_message() function
if (message.author.bot): #check if the author is a bot
await message.reply('Hello, bot!') #reply to the bot

Discordjs: Specifying channel for an interaction.reply

I am using Discordjs v13. I have created a slash command and I am able to "print" a message using
await interaction.reply(messageObj);
I need to send the reply to a different channel where the command was triggered, is this possible?
Something like:
interaction.setChannel(channelId).reply(...)
OR
interaction.reply({
channel: ....
....
})
What you want is not possible. The Discord API does not allow to specify the channel where the app interaction should be replied in: https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction
However if you are concerned with the reply being shown to everyone, you can make the reply ephemeral. If you want to log interactions, you can reply to the interaction then send another message using the solution provided in the comments of your question.
this is actually possible in discordjs v14 and may be in v13 as well. Carl-bot does it with suggestions.but its not an actual reply
use
interaction.guild.channels.cache.get('channel-id').send('message')
this will send a message in a the select channel you may still want to
interaction.reply({Content:'replied in #channel' [embed], ephemeral: true })
so the user knows the reply was redirected . ephemeral: true makes the replay only visible to the user that evoked the interaction.
and if you need the message id for the new message use
const msg = await interaction.guild.channels.cache.get('channel-id').send('message');
to send the message and you can do something like const messageid = msg.id

Discord bot : How to know when a user is pinged in the message and not because it's a reply

The goal :
I am trying to get the bot to send a message when a specific user is pinged in a message.
So I tried with this :
if (message.mentions.has(bot.users.cache.get(userID)))
And it's working fine, if you ping the user, the bot sends a message. Excepted...
The problem :
The bot also react when you simply reply to the user without pinging the user in the message, and I don't want that.
The only way I can see is :
if (message.content.includes(userID))
You should check directly if they were pinged in the message.
const userRegex = new RegExp(`<#!?${userID}>`)
if (message.content.match(userRegex)) {
//user has been mentioned and it was not because of reply
}

Discord.js Bot that can send a embed message

I will refer to this picture:
I am making a Discord bot in JavaScript and I am stuck somewhere
I have a say command which you use like !say Text here and the bot will send a plain message saying Text here
Now I want the bot to send an embed message used the same and I want the bot to have a title, image, link and a author set on default. When someone does !sayEmbed #everyone loco (the text there)
There you go:
client.on("message", function(msg){
if (msg.content.split("!")[0] != "sayEmbed") return;
if (msg.content.split(" ")[1]){
// if args exist
msg.channel.send(new MessageEmbed()
.setTitle("Genius Mind")
.setDescription(msg.content.split("!sayEmbed")[0])
.setColor("#148837")
.setAuthor(`#everyone react now | {msg.createdAt.toDateString}`)
.setURL("someURL.example.com")
.setThumbnail("foo.bar/link/to/image")
)
}
}
I couldn't find any url and image url, so change that yourself.

Reply to anyone who sent a DM

EDIT: Another question with better answers: How to reply to any DMs sent to the bot?
Is it possible to reply to someone who sent a message to my Discord.js bot?
For example, when someone sends hi to my bot's DMs, the bot should reply Please use !help for the commands' list.
I've tried a lot of attempts to use the MessageCollector but I failed doing it.
Any help would be appreciated.
Thanks!
You can just tell the bot to do that with client.on('message').
Try this:
client.on('msg', () => {
if (msg.channel.type == 'dm' && msg.content.toLowerCase() == 'hi')
msg.channel.send('Please use !help for the commands' list.')
})
This is just a quick example, but you can also add checking for commands and all the other stuff that you do on normal guild channels. To check if the message comes from a DMChannel is to check Channel.type

Resources