Reputation: 25
I am new to discord.js and want to know how I would make the bot say something different depending on the ${message.author}
.
For example:
Person 1: !hello
Bot: Nope, goodbye.
Person 2: !hello
Bot: Oh, hello!
My command handler has this sort of thing in the main/index.js:
if(command === 'hello'){
client.commands.get('hello').execute(message, args);
and in a JS file called "hello", it has this:
module.exports = {
name: 'hello',
description: 'example message',
execute(message, args) {
message.channel.send(`example`);
}
}
If the bot could check who is typing in this sort of format, that would be really useful, thanks. Sorry for my lack of understanding.
Upvotes: 1
Views: 63
Reputation: 23
You can check the documentation https://discord.js.org :)
https://discord.js.org/#/docs/main/stable/class/Message for Message
,
https://discord.js.org/#/docs/main/stable/class/GuildMember for GuildMember
(a member in a guild),
and https://discord.js.org/#/docs/main/stable/class/User for User
.
execute(message, args) {
message.channel.send(`Hello ${message.author.tag}`);
}
This would return Hello user#0001
.
execute(message, args) {
switch(message.author.tag) {
case 'person1#0001':
message.channel.send(`Nope, goodbye.`);
break;
case 'person2#0002':
message.channel.send(`Oh, hello!`)
break;
default:
message.channel.send(`Hello, ${message.author.tag}!`)
break;
}
If the author is person1, the bot will reply "Nope, goodbye."
If it's person2, the bot will reply "Oh, hello!"
And if it's another person, the bot will reply "Hello, user#0001" (with the tag of the user)
Upvotes: 1
Reputation: 23160
You can check the author's id, tag, etc. If it's the one you're looking for, send a message with hello, if not, say goodbye:
execute(message, args) {
if (message.author.tag === 'hydrabolt#0001')
return message.channel.send(`Hello, ${message.author}!`);
return message.channel.send('Nope, goodbye!');
}
execute(message, args) {
if (message.author.id === '844191247870591006')
return message.channel.send(`Hello, ${message.author}!`);
return message.channel.send('Nope, goodbye!');
}
Upvotes: 2