How to react to a specific message (discord.py) - discord

I'm coding a suggestion bot that's supposed to send a player's suggestion to a suggestions channel in my server and react in the suggestions channel with some emojis.
The problem is that using 'message' as the Message parameter would react to the message sent to trigger the code, but I want it to react to the message the bot sent to the suggestions channel. I'm fairly new to coding. How can I get the bot to react to a message in a different channel?
text_channel = client.get_channel('527127778982625291')
msg = 'Your suggestion has been sent to '+str(text_channel.mention)+' to be voted on!'
await client.send_message(message.channel, msg)
msg = str(message.author.mention)+' suggested "'+str(repAdder)+'"'
await client.send_message(discord.Object(id='527127778982625291'), msg)
print(message)
await client.add_reaction(bot_message, ":yes:527184699098136577")
await client.add_reaction(bot_message, ":no:527184806929235999")
await client.add_reaction(bot_message, '🤷')

You needed to add the reaction to the message that the bot sent, not the user-sent message.
Passing the bot-sent-message as a Message object to client.add_reaction() instead of the original message should fix the problem.

Related

How to react to interacton (djs v13)

How do I react (with an emoji) to an interaction message via. discord.js v13? If it's too difficult of a task, I'd rather just come up with an alternative instead of a long complex expression. If you know how, let me know!
Thanks.
As Christoph pointed out, interactions are not messages. They're events that are fired at your client, and you're expected to reply to either with a new message, edit the origin message, or soon a modal.
If you want to reply to a command then react on your reply, you can do it like so:
// replied is an instance of CommandInteraction
const replied = await interaction.reply("My message")
await replied.react("👍")
But you cannot react to the actual command, as the command isn't a message, it's an event. That just replied to the command normally with a message, then reacts on the bot's message.
If you want to react on a message when a button in that message is clicked, you can do that like so:
// interaction is an instance of MessageComponentInteraction
await interaction.deferUpdate() // this stops it erroring, as we don't actually reply to the button
await interaction.message.react("👍")
Which will defer the button (tells discord we don't want to reply, so we don't get "Interaction failed"), then react on the message which the button is a part of.

discord.js access to existing message and get reaction count

Hope you could help me a bit on this. I'm trying to code a small function but I am sure to miss something quite obvious here... I tried with the help of many previous messages, but most of them are old discord.js version (I'm on V13)
My code goal is : from the ID of a message, i would like to catch the number of reactions of a specific emoji. I must precise that this is on existing message, not on the event of new message arriving or new reaction. It will be triggered by a cron function.
Other precision : The message will be posted & reacted after the bot is online
channel = client.get_channel(CHAN_CHALLENGE_ID);
message = await channel.fetch_message(messageID);
MyValue == message.reactions.cache.find(reaction => reaction.emoji.name == MyEmoji).count;
I get the error code "client.get_channel" is not a function
Thank you very much in advance for your help !!!
Get Channel
Discord.js: GuildChannelManager
const channel = guild.channels.cache.get('CHANNEL ID');
Get Message
Discord.js: TextChannel: messages
const message = await channel.messages.fetch('MESSAGE ID');

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

How can i edit and redesign my old embed messages

ive been texted something on my discord server before as embed. and now i just wanted to edit my old embed messages to redesign how its look by rewrite something and change colors.
how can i edit a specific embed messages by message id? i know it can edit itself by using :
first_embed = Embed(title='embed 1')
new_embed = Embed(title='embed 2')
msg = await ctx.send(embed=first_embed)
await msg.edit(embed=new_embed)
but i don't really know how to make it works. how it can edit at message ids? like checking its own id?
I am not 100% sure if I understand your question correctly, but to edit messages you could fetch them like this:
message = await ctx.fetch_message(message ID)
Or you can just use the integrated message converter in the arguments of the command.
#bot.command()
async def edit_embed(ctx, message: discord.Message):
#define the new embed here
await message.edit(embed=new_embed)
The user has to supply the message ID or message URL directly as an argument and discord.py will automatically convert it to a message object. Keep in mind that if you use the message ID, you will have to use the command in the same channel as the message you want to edit.
You have to make a new command to edit embeds and get the embed message's ID and the stuff you want to change as parameters. Then you can to Embed.copy() or Embed.to_dict() to get embed's data and then update the data you got as parameter.
An example would be:
#bot.command()
async def editembed(ctx, channel: discord.Chanel, msg_id, title, color):
msg = await channel.fetch_message(msg_id)
embed = msg.embeds[0].to_dict()
embed["title"] = title
embed["color"] = color
await msg.edit(embed = discord.Embed.from_dict())
Note: bot has no fetch message attribute so you have to either get it from channel or context (while using context you have to send the command on the same channel as the message to be edited)

Discord bot that sends an message to a channel whenever a message is deleted. Discord.js

I’m trying to make my bot send a message to a channel whenever a user deletes his/her message, sorta like the bot Dyno, but I do not know how to do this. I think the method is .deleted() but I can’t seem to make it work. Can anyone tell me how? Sorry for lack of detail, there’s nothing else to add. Thank you in advance.
The Client (or Bot) has an event called messageDelete which is fired everytime a message is deleted. The given parameter with this event is the message that has been deleted. Take a look at the sample code below for an example.
// Create an event listener for deleted messages
client.on('messageDelete', message => {
// Fetch the designated channel on a server
const channel = message.guild.channels.cache.find(ch => ch.name === 'deleted-messages-log');
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send a message in the log channel
channel.send(`A message has been deleted. The message was: ${message.content}`);
});

Resources