I have my bot reacting to messages when messages contain a certain string, let's call it STRING. However, that certain string is also in the name of custom emojis, referred to as EMOJISTRING. I would like to be able to detect:
if (message.content.includes("STRING") && !message.content.includes(":EMOJISTRING:")) {
message.react('CUSTOM_ID');
}
However, this does not work as intended, and all messages with the STRING still get the bot reactions, whether or not it contains EMOJISTRING. Printing the incoming messages containing custom emojis to console gives DiscordAPIError: Unknown Message.
How should I detect a custom emoji in an incoming message by its name, e.g. :custom_emojistring:?
Maybe you should try this:
if (message.content.includes(" STRING ") && !message.content.includes(":EMOJISTRING:")) {
message.react('CUSTOM_ID');
}
As the emojis can't have spaces at their names, that should only fetch the "STRING" you want.
Related
I have coded a bot to send a message response to a given command, !a. I want to store additional data on the message object, so that if the user reacts to that message the bot can read the hidden data property and know the original message resulted from !a.
Ideas I had:
Create a custom property on the message object: Message.Custom_Prop
Hijack an unused property: Maybe Message.webhookId?
Store hidden text in the form of an embed or message content.
I haven't been able to get any of these to work though.
The best way that I can think of is to store an array of message IDs that were triggered by !a. Something like this:
// At the start of your script
const commandResponses = [];
// Logic for sending the command response
message.channel.send("response here").then(msg => commandResponses.push(msg.id));
// Checking whether the message was a response
if (commandResponses.includes(reaction.message.id)) {
// It's a response so do stuff here
}
(Not tested so it's possible that this won't work)
I am making a discord bot that reacts to images sent by users with an appropriate emoji/reaction that is determined by a CLIP model, it all works perfectly until I try to react to a message with m output. I can send the emojis as replys or messages but if I try to react to a message with the emoji I get the errror:
discord.errors.HTTPException: 405 Method Not Allowed (error code: 0): 405: Method Not Allowed
The code I'm trying to execute is:
file_ = filename
print("classifying")
reaction = classify(file_)
print(reaction)
await message.channel.send(reaction)
and this code always returns something like this when I try to send it to a channel without it being a reaction:
classifying
⛲️
any suggestions to get it to use these emojis as an actual reaction within the discord.py API?
Assuming that the output of your classification is a Unicode Emoji, we can simply use the add_reaction method.
file_ = filename
reaction = classify(file_)
await message.add_reaction(reaction)
In the above example, our message variable is an instance of the Message Class.
Given a discord message id and a channel id, is there a way of finding the previous message to the same discord channel?
Message ids are intigers, and my impression is that the are monotonously increasing. So if there was a way of looking up all the message ids that a channel has recieved, i think it would be as simple as finding the highest that is less than the id you are interested in.
Im not sure if u meant to find the content of the message itself or the previous message before it but you can read more on txt_channel.history here:
What history does is enabling you to see the message history of a text channel.
So if you want to find the contents of a specific message using it's id you can do:
(of course you need to fetch the text channel, you can look at here)
async for msg in txt_ch.history(limit=[how many messages back you want the loop to go]):
if msg.id == ID_OF_MSG: # you found the message
print("the message with the id has been found")
now this code ^^ is pointing you to the message you gave with the current id but if you want to get the message previous to it you just add this:
async for msg in txt_ch.history(limit=[how many messages back you want the loop to go]):
found_message = False
if msg.id == ID_OF_MSG: # you found the message
found_message =True
elif found_message:
found_message = False
print("previous message")
Of course you can change the last line on the print to something like:
print(msg.content)
to see it's content, or you can send it back to the channel, it is up to you.
side not:
I tried to test it and it doesn't seem that the ids of the messages are one after another so you can't do id-1 to get the previous message id.
I made a code in which he sends a message to people with a specific role, however, for some reason it is sending only to me, code below
canal.send(`||#everyone||`, embed).then(message => {
message.react('748309940795473980')
})
servidor.roles.cache.get("771492474594000928").members.forEach((membro) => {
console.log(membro.user.username)
membro.send(`${membro}`, embed)
})
I would like you to help me with this, this command does the following functions:
Send Message to One Channel (Working)
Send Message to People with a Specific Position (Not Working, Just Send to Me)
As You Can See, I tried to put console.log, however, he was supposed to appear the name of everyone who received the message, but no, only my name appears, and only I get the message
I Need to Get This Working!
Is possible to extract a variant code from any incoming webhook and make bot send a new message with only that variant code?
Webhook example:
I think that what you mean is: How can I extract text from an embed sent by a webhook?
Webhooks often send embeds, just because is a prettier way of sending data. The thing you see when you send a YouTube or Twitter link is also an embed.
If this is the case, I'll assume that the embed you're referring to is the first and only embed of the message. I'll also assume that message is the message sent by the webhook.
let embed = message.embeds[0], // This is the embed we're searching in.
field, text, number;
if (!embed) return; // If there are no embeds in the message, return.
for (let f of embed.fields) { // Loop through every field in the embed...
if (f.name == 'Sizes') { // ...until you find the one named 'Sizes'
field = f; // Then store it into the field variable
break; // Exit the loop
}
}
if (!field) return; // If there are no 'Sizes' fields, return.
// This will split the message in two parts to get the 2nd
// It will get the string cantaining the number
text = field.value.split('-')[1].trim();
// If you want the result as a number, you can parse it:
number = parseInt(text);