Reply to anyone who sent a DM - discord

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

Related

Discord Autocode reaction reply bot (not reaction role bot)

I have been using autocode.com to create some Discord bots. I have very little programming experience and found autocode to be quite easy. However, I've tried asking a question on autocode's discord that no one seems to understand or is asking.
I am trying to create a bot that replies to reactions--but does not assign roles, but instead, provides a reply--either in thread or a DM to that user who uses that specific emoji reaction.
For example, this is what I am looking to do: if there is a bot message in #channelx, userX will react to that message with a pepperoni emoji and then a pizza bot will reply back with a message either in thread or DM such as, "Hi #userx, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order".
Autocode has a bot that can react to reactions and assign roles but I can't seem to reverse engineer it give a reply, rather than assign roles.
I appreciate any assistance. Thanks!
What does autocode use? Python or node.js? If python, you can do something like this:
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('message'):
await message.channel.send('hi')
If node.js, you can do something like this:
client.on('messageCreate', msg => {
if (msg.content === 'specific message') {
msg.reply(`response text`);
}
});
I was previously a Community Hero at the Autocode Discord server. Try finding another app through this, and if none are available, the thing to do would be looking through the API's. Here's one for messaging in general, here's one for responding, and here's one for dm-ing.
Let's say, for example, I'd be making it reply to a reaction through DM:
The first thing you do is make sure the event trigger is set to message.reaction.add. This is so that the code you will write is triggered whenever a reaction is added.
Make either a switch or if statement to change what happens depending on what reaction triggers the code. In this example, I'll just use an if statement for easy explanation.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.emoji.id == '1234567890') {
await lib.discord.users['#0.2.1'].dms.create({
recipient_id: `${context.params.event.member.user.id}`,
content: `Hi <#${context.params.event.member.user.id}>, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order`
});
}
What this does is check if the thing that triggered this event has the emoji id equaling '1234567890': If it does, then it follows into that if statement, and if it does not, it skips over it.
In the future, please stay patient in the Autocode Discord server; The ones who are helping are also community members, similar to here. You may always ask the same question every now and then.

How to Introduce the Bot [On added to server]

I have a question regarding on how to detect if my discord bot was added to a server. I want to display an embed when they are added, an example would be:
Can someone tell me how to do this? Thanks.
You can use the
<Client>.on('guildCreate') event.
https://discord.js.org/#/docs/discord.js/stable/class/Client?scrollTo=e-guildCreate
It's simple
I suppose you want to send a message in the guild when the bot is added
client.on("guildCreate", async (guild) =>{
guild.systemChannel.send({content: `Thank's for adding me into your server`})
})

How to make bot change channel permissions?

So, the Discord bot that I'm making is sort of a server manager kind of thing and I'm making a channel lock command which basically makes it so people can't send messages in the channel.
How would I make it so that when someone types the command it turns the 'Send Messages' permission FALSE?
Any help is appreciated! Thanks.
const Channel = client.channels.cache.get("ChannelID");
if (!Channel) return console.log("Invalid channel ID.");
Channel.updateOverwrite(message.guild.roles.everyone, {SEND_MESSAGES: false});

I'm making a discord bot and want it to DM a user

So I'm making a kick command for my discord bot and I want the bot to DM the user telling them they have been kicked. So far I have got:
case 'kick':
const Embed = new
Discord.MessageEmbed()
.setTitle('Success!')
.setColor(0x00FF00)
.setDescription(`Successfully kicked **${args[2]}** \n \n**Message:** \n"${args.join(' ')}"`)
if(!message.member.hasPermission(['KICK_MEMBERS'])) return message.channel.send('*Error: You do not have permission to use* **kick**.');
if(!args[1]) return message.channel.send('*Error: Please specify a user to kick!*');
let member = message.mentions.members.first();
member.kick().then((member) => {
message.channel.send(Embed);
})
break;
So far, the user is successfully kicked so all this works.
All I need to know is how to make the bot DM the mentioned user to tell them they have been kicked. Any help is appreciated!
You are probably looking for this method: GuildMember#send()
member.send("Your DM Here");
Note that if the only reason your bot could send a member DMs was because of a mutual server in which the user had DMs from server members enabled (user disabled other types of stranger DMs), then your bot would not be able to send the DM. It would probably be a good idea to send them the DM and wait for the method's returned promise to resolve before kicking them, for a higher chance that the DM actually reaches them.

How do I "Link" a channel like a mention in my Discord Bot message?

I'd like our Discord Bot to mention a specific channel, and let it be clickable. I understand mentioning a user you use the user ID. I do have the channel Id, just unsure how to implement it.
You just have to do the following:
message.channel.send('Please take a look at this Discord Server channel <#CHANNELID>')
or if you get the channel id from the bot
const channel = message.guild.channels.find(channel => channel.name === 'Name of the channel');
message.channel.send(`Please take a look at this Discord Server channel <#${channel.id}>`)
Then the channel is clickable like in this screenshot:
It is simple :^)
<#channel.id>
Channels on Discord have this special kinda syntax here:
<#channel id>
As commented by Elitezen here, running toString() on a Channel can do that mention for you. Then, just send that string yourself. It's much simpler than manually doing it.
Like this if you're answering a message:
message.channel.send(message.channel.toString());
Also, like answered by others in this question, you can do that yourself if you feel like it.
If you have a Channel object already, you can do something like this (imagine your channel is named myChannel - it doesn't have to be named that, though):
message.channel.send(`<#${message.channel.id}>`);

Resources