This interaction failed even with await interaction.respond - discord.py - discord

I have a command that uses discord dropdown menus or select lists. It used to work completely fine, but for some reason it now starts to say 'This interaction failed'. I know I need to use reaction.response, but for some reason it doesnt work. Yesterday, it worked perfectly fine, and there wasnt anything that I changed really. But now for some reason whenever I choose something, it immediately says 'this interaction failed'. The only thing I changed was that I was solving out how to get the active dev badge, and im currently waiting for it. Other than that, I didnt change ANYTHING at all. This is my code:
if message.content.startswith('c!help'):
select = Select(placeholder="Choose a category",
options=[
discord.SelectOption(label="Fun commands",
default=False),
discord.SelectOption(label="General commands",
default=False),
discord.SelectOption(label="Seasonal commands",default=False)
])
view = View()
view.add_item(select)
await message.channel.send(embed=fhelp, view=view)
async def call_back(interaction):
mainthing = select.values[0]
if mainthing == "Fun commands":
await interaction.response.edit_message(embed=fhelp, view=view)
elif mainthing == "General commands":
await interaction.response.edit_message(embed=ghelp, view=view)
elif mainthing == "Seasonal commands":
await interaction.response.edit_message(embed=shelp,view=view)
select.callback = call_back
I made everything clear, and please dont avoid the main question. It worked completely fine. I doubt there is a problem with my code since I didnt even change anything in it, but it just suddenly started saying that error in an instant. I believe its probably a bug or something related with the active dev badge thing.

Related

Add / Remove reaction event no longer firing Discord.js v13

Good morning everyone,
I am currently running into one pretty irritating issue with getting a users messages from before the bots launch. I have been able to do this in the past (a few months ago), but it seems they have replaced the Intents.FLAGS approach for GatewayIntentBits. This has not been to complicated to change, but some problems have occurred.
One of the biggest issues, and the reason for this question is that even though I contain data in my intents that would allow for reading of reactions, as well as adding partials (I read it may help online). This does not seem to fix the issue.
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers], partials:["Message", "Channel", "Reaction"]})
. . .
client.on('messageReactionAdd', _ => {
console.log('a reaction has been added');
});
client.on('messageReactionRemove', _ => {
console.log('a reaction has been removed');
});
I know this isn't allot to go off of, but I have tested it with barely anything in my application and I still run into this error. Is this a known issue with the change to GatewayIntentBits? I would love to continue working on this bot.
Thank you for any assistance you may be able to provide.
EDIT: I have managed to get the reactions to work on the application now. I have not even started touching those old messages, and its working. Thank you for your help. My best bet of why its working is that the messages needed to be resent with the partials and intents specified above. I dont know why this didnt work before, but whatever.
Your gateway intent bits are fine, you need to do something similar to that for the partials as well, you need to import partials from discord.js and use them like that.
const { Client, Partials } = from 'discord.js';
const client = new Client({
intents: [],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
});

Message object .edit() stops working after some time

First I create an object
var queue = {1:{},2:{},3:{}};
And then I store the message based on QueueKey, or edit if it's already created
if (typeof queue[QueueKey].messageOBJ == 'undefined')
{
queue[QueueKey].messageOBJ = await configChannel.send({ embeds: [getEmbedFloor(QueueKey)] });
}
else
{
queue[QueueKey].messageOBJ = await queue[QueueKey].messageOBJ.edit({ embeds: [getEmbedFloor(QueueKey)] });
}
everything starts working well but after sometime(1~2 hours) bot stops editing the already created message, looks like it lose object reference.
It not pops any error message or code break, seems like the message was edited sucessfully but the real message in discord still the same
I'm thinking in store the messageID instead the whole object and search for the message ID with .fetch() but this will lead to other problems
is there any way to store message Objects properly?
I discovered my problem, actually bot was editing the message to frequently, so after some time discord "auto ban" my bot for some time, something like a cooldown, só it starts to get slower and slower, up to seems like it is stuck.
My solution was check message before edit, to compare if the changes in message are really necessary, before edit or not

Discord.js - Getting multiple reactions to execute a command through awaitReactions method

I'm currently in the process of making a little game of TicTacToe, and the idea I had in mind is to make it so instead of the channel being spammed with constant embeds asking for the person's next move, is to simply make it reaction-based, where you get to pick 1 out of 9 reactions (And of course, you wont be able to pick it again if the other player has already picked it).
I have never really worked with requiring multiple reactions, therefore I'd like to ask your help on how exactly to make it so that the message command execution isn't a one-time thing, but will go on until there's eventually a winner.
So far, with the code I have written, this does work 2 times, but then it randomly stops and no longer works.
In addition, when I'm trying to declare a spot as an x or a circle, the spot turns completely blank.
Please help!
The code I have so far:
https://sourceb.in/S7cayfoYjp
Edit: I have now also found that the bot at first kind of skips the whole awaitReactions code. I used 'console.log(i)' for this, so that every time it loops it prints out 'i', and it seemed to be printing out the numbers 0-8 immediately, meaning it's not properly going through the code.
I think what you can use best there is a reactionCollector. It's a temporary reaction listener, attached to a message. A sample code for that would be:
const msg = await message.channel.send('tic tac toe test');
const acceptedEmojis = ['↖️', '⬆️', '↗️', '⬅️', '⏺️', '➡️', '↙️', '⬇️', '↘️']
const filter = (reaction, user) => {
return acceptedEmojis.includes(reaction.emoji.name) && user.id === turnId;
}
//here you create the collector. It has following attributes: it stops after 10 minutes or after 2 minutes of not collecting anything.
const collector = msg.createReactionCollector(filter, { time: 600000, idle: 120000});
//here you start the listener
collector.on('collect', (reaction, user) => {
if (reaction.emoji.name === '↖️') {
//remove the reaction
await msg.reactions.resolve('↖️')
acceptedEmojis.splice(acceptedEmojis.indexOf('↖️'), 1);
//rest of your code...
} else if (reaction.emoji.name === '⬆️') {
...
}
});

Discord.py bot speak message

I have been looking for a way to make a bot speak out loud an edited message, using tts=True works fine when the message is first send. However, it doesn't work when it is edited. Here is the code I have tried.
msg = await ctx.send(content='Hello world', tts=True)
await msg.edit(content="I said hello", tts=True)
Couldn't find anything on google. Hopefully, somebody here knows how to do it.

How can I find the reason for a ban through discord audit logs? (Using Discord.js)

What I'm trying to do is make a log for my bot, (you know, something to record server events as they happen), and I've been doing alright so far, but I just can't seem to figure out how to get the reason for a ban/kick or whatever else can record reasons. I've checked the documentation, and I just can't really figure out what some of the stuff there means. There isn't really code to show off, because I have no clue where to start here, and it's about time I ask somewhere for help.
Edit: I do know where to start, I can find the audit log entry, but I can't get the reason for the entry
You can use guild.fetchAuditLogs()
const guild = client.guilds.cache.get('Guild_ID')
const fetchedBan = await guild.fetchAuditLogs({ user: 'User_ID), type: 'MEMBER_BAN_ADD' })
You can also use message.guild instead of const guild = client.guilds.cache.get('Guild_ID')
To get the reason for the latest ban of that member
const banReason = fetchedBan.entries.first().reason

Resources