How to Make a Bot React to Its Own Message

How do I make the bot react to its own message and edit the previous sent embed?

I have tested your code and came up with a solution.

When you call the reaction collector you do:

message.awaitReactions({ filter, max: 1, time: 60000, errors: ['time'] })

And filter is your filter function, however I determined that the filter function is meant to be the first argument in the function, and the rest of the options is the second argument, thus the line should look something like this:

message.awaitReactions(filter, { max: 1, time: 60000, errors: ["time"] })

You got the code to edit the embed right

Essentially Your final code should look something like:

I took some liberties in formating the code and moving a few things around

module.exports = {
name: "emoji",
group: "misc",
aliases: ["emoticon"],
description: "mostra ajuda.",
use: ".help <comando>",
async execute(message, args) {
try {
const filter = (reaction, user) =>
reaction.emoji.name === "▶️" && user.id === message.author.id;

let ajuda = new Discord.MessageEmbed()
.setColor("#0099ff")
.setAuthor(
`Comando por ${message.author.username}`,
message.author.displayAvatarURL({ dynamic: true }),
message.url
)
.setTitle(`**Ajuda**`)
.setDescription(
"**Modo de uso:** .help <comando> \n _Exemplo: .help config_"
)
.addFields({
name: "**config**",
value: "shows config commands",
})
.setTimestamp()
.setFooter("[PRD] Corridas todos os direitos reservados.");
await message.channel
.send({ embed: ajuda })
.then(function (message) {
message.react("▶️");

message
.awaitReactions(filter, {
max: 1,
time: 60000,
errors: ["time"],
})

// When a reaction is collected
.then((collected) => {
let newEmbed =
new Discord.MessageEmbed().setDescription("a");

// Edit the embed
message.edit(newEmbed);
})
.catch((err) => {
console.log(err);
});
})
.catch(function () {
//Something
});
} catch (error) {
console.log(error);
}
},
};


Getting bot to react to it's own message

You have the right idea but you add the reaction to the wrong message. To react to the message the bot has send, you can use the Promise returned by TextChannel.send(). Take a look at the example code below and give it a try:

module.exports = {
name: "ping",
description: "Basic ping command",
execute(message) {
message.channel.send("Pong.").then((botMessage) => {
botMessage.react("quot;);
});
},
};

Discord.py - Make a bot react to its own message(s)

In discord.py@rewrite, you have to use discord.Message.add_reaction:

emojis = ['emoji 1', 'emoji_2', 'emoji 3']
adminBug = bot.get_channel(733721953134837861)
message = await adminBug.send(embed=embed)

for emoji in emojis:
await message.add_reaction(emoji)

Then, to exploit reactions, you'll have to use the discord.on_reaction_add event. This event will be triggered when someone reacts to a message and will return a Reaction object and a User object:

@bot.event
async def on_reaction_add(reaction, user):
embed = reaction.embeds[0]
emoji = reaction.emoji

if user.bot:
return

if emoji == "emoji 1":
fixed_channel = bot.get_channel(channel_id)
await fixed_channel.send(embed=embed)
elif emoji == "emoji 2":
#do stuff
elif emoji == "emoji 3":
#do stuff
else:
return

NB: You'll have to replace "emoji 1", "emoji 2" and "emoji 3" with your emojis. add_reactions accepts:

  • Global emojis (eg. ) that you can copy on emojipedia
  • Raw unicode (as you tried)
  • Discord emojis: \N{EMOJI NAME}
  • Custom discord emojis (There might be some better ways, I've came up with this after a small amount a research)
    async def get_emoji(guild: discord.Guild, arg):
    return get(ctx.guild.emojis, name=arg)

How do I make my Discord.JS bot react to it's own Direct Message?

Send a message to your target, pass the message into a .then(), Where the bot will react to the message

message.member.send(<theMessage>).then(msg => {
msg.react('<emoji>')
msg.react('<emoji>')
msg.react('<emoji>')
})

discord.py add reaction to own message

.send() returns a new Message object of the message sent. You'll want to add the reaction to that message instead.

new_msg = await message.channel.send("hello!")
await new_msg.add_reaction("quot;)

How do I make the bot react to itself with 2 different reactions

Try this:

message.channel.send(embed)
.then(sentMessage => {
sentMessage.react('')
sentMessage.react('')
});

If you want your bot to react in order you have two options:

Option 1:

Use async / await:

message.channel.send(embed)
.then(sentMessage => {
// Don't forget to make your function async, otherwise it won't work
await sentMessage.react('')
await sentMessage.react('')
});

Option 2:

Chain .then()'s:

message.channel.send(embed)
.then(sentMessage => sentMessage.react(''))
.then(sentMessage => sentMessage.react(''))
});


References:

  • Official guide


Related Topics



Leave a reply



Submit