I'm having problems editing my embeds after a button click, it just won't edit it, and after the 10 second timeout for collector.on("end...) has passed, it edits the embed, adding the message on top, and shows the "DiscordAPIError: Unknown Message" error without deleting the embed. I thought maybe it wasn't getting the embed from the "reply" constant but I used console.log and it shows the embed in the console, I checked the userEmbed constant as well and it also showed. What is the problem?
Here's the code:
async execute (interaction, client) {
const reply = await require('../../commands/entertainment/give')
const userEmbed = await require('../../commands/entertainment/give')
const collector = await reply.createMessageComponentCollector({
filter: (i) => i.user.id === interaction.user.id,
time: 10000
});
collector.on("collect", async (i) => {
await i.update({ embeds: [userEmbed], ephemeral: true });
})
collector.on("end", async (c) => {
await reply.edit('Too slow');
})
here's where the embed is being sent initially. I'm using module.exports since I'm using a Button Handler to handle buttons on a different file. My intention is to have the buttons removed from the embed after a button is clicked and send a different embed if the cancel button is clicked. And have the embed replaced with a message if no button is clicked after 10 seconds.
const reply= await interaction.reply({ embeds: [userEmbed], components: [row], ephemeral: true, fetchReply : true})
module.exports = reply;
Related
I am trying to kick off some behavior within our application from a notification that is created using the Notification API. I doing this with some success, but we need the same behavior whether the user clicks the notification or closes the notification by clicking the X and for whatever reason the onclose event does not fire regardless of browser. This is a react application and the code looks something like this:
`async function showNotification() {
if (Notification.permission !== "granted") {
await Notification.requestPermission()
}
if (Notification.permission === "granted") {
const notification = new Notification('New Camera Alerts', {
body: 'There are new notifications to review in the Notification Panel',
icon: `${logo}`,
requireInteraction: true // this makes the dialog stay open until someone clicks it
})
const testEvent = (event: Event) => {
event.preventDefault()
// more lines of code here with what should happen when the
// notification is clicked/closed
}
notification.onclick = (event) => testEvent (event)
notification.onclose = (event) => testEvent (event)
}
}`
What I tried is assigning the same function call to both the click and close handlers. I was expecting both actions to have the same behavior. What actually happens is the close event is never fired at all.
I've attempted for a while now to try and get msg.channel.send({ embeds: [embed] }) to work however I keep getting DiscordAPIError: Cannot send an empty message
I should note that all code is in a module however all the proper resources are required so I'm at a total loss here, we are also running Discord.JS v12.2.0.
Here is what we have:
const Discord = require("discord.js")
exports.run = async (client, msg, args) => {
let embed = new Discord.MessageEmbed()
.setTitle("Test")
.setColor("#00F0FF")
.setTimestamp();
client.log(JSON.stringify(embed.toJSON()), 1)
msg.channel.send({ embeds: [embed] }).then(() => {
}).catch(err => {
client.log(err, 2)
});
}
Just another note, even if I do provide the content index it posts the message just without the embed.
I can also do msg.channel.send(embed); and it posts the embed, however I am needing to post multiple embeds without spamming discords api.
You are using v12, but { embeds: [] } is only in v13. You should either update to v13 or use the old way
msg.channel.send(embed)
I am making a webapp using react and ethers.js that works with metamask. If I call MyContract.MyFunc(xyz, function(error, result){ }); user will see a metamask popup. My code will get a response only if user presses SUBMIT or REJECT. But if the user refreshes the page without pressing either SUBMIT or REJECT, my code will never know the status of this transaction although the user is still able to submit this transaction.
The first part of my code sends a transaction and the second part posts info to my api. My issue is that the transaction part of the code produces a metamask popup for the user to confirm and sign the transaction. If the user continues with the transaction as expected my code work without problems. However, if the user refreshes the page or otherwise resets the state of my component after the metamask popup is produced and before they confirm it and then confirm it after the page reload, then I'm unable to post the data to my api and my app breaks. What can I do to stop this? Is there a way to reject transactions on page reloads or check if there unsigned transactions on metamask?
try {
const price = await connectedContract.getMintPrice();
const transaction = await connectedContract.primeMint({
value: price,
});
const receipt = await transaction.wait();
blockNumber = receipt.blockNumber;
} catch (err) {
console.error(err);
setState({ ...state, button: false });
}
axios
.post("http://localhost:5000/api/mints", {
_id: _address,
blockNumber: blockNumber,
})
.then(() => {
setState({
status: "Loading",
blockNumber: blockNumber,
button: false,
});
})
.catch((err) => {
console.error(err);
setState({ ...state, button: false });
});
I'm trying to log the Discord event when someone is moving any channel.
The channelUpdate event works almost like a charm and returning 2 events (two, because of when you moving one channel the rawPosition property is changing in the target's channel and in the channel you swiped the place). Except strange cases when you moved one channel and getting tone of events as if you moved all the server channels at ones. Weird thing, yep.
The problem is the "channelUpdate" event returns only oldChannel and newChannel but not the executor data (who and when).
I've tried to use guild.fetchAuditLogs({ type: 14, limit: 1 }) but looks like it's not returning changing position events. One gets the feeling Discord's log engine is not logging this event OR I'm looking in wrong place. Also tried type 11 and even NULL with no luck on finding rawPosition prop changing.
Please, help me to find the way how to log WHO is changing the channels position or tell me it's not possible at the time.
Some code here:
const Discord = require('discord.js');
const client = new Discord.Client({ shards: 'auto'});
const { prefix, token, witaitoken , guildID, DBUser, DBPass } = require('./config.json');
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity(`Star Citizen`, { type: 'PLAYING' });
});
client.on('channelUpdate', (oldChannel, newChannel) => {
if (oldChannel.rawPosition !== newChannel.rawPosition) {
oldChannel.guild.fetchAuditLogs({ limit: 10 })
.then( (audit) => {
const log = audit.entries;
if (!log) return;
fs = require('fs');
fs.appendFile('audit.txt', JSON.stringify(log), function (err) {
if (err) return console.log(err);
});
})
}
});
client.login(token);
client.on("error", (e) => console.error(e));
client.on("warn", (e) => console.warn(e));
client.on("debug", (e) => console.info(e));
I wanna use an bot to react to every single message in an channel using discord.js f.e. i got an emoji contest channel and i wanna ad an ✅ and an ✖ reaction on every post in there
ofc, all the unnecesary messages are cleaned up so that there are like 50 messages
Fetch the messages already sent in a channel with TextChannel.fetchMessages().
Iterate through the Collection.
Add reactions with Message.react().
When a new message is sent in the channel, you should also add the reactions.
const emojiChannelID = 'ChannelIDHere';
client.on('ready', async () => {
try {
const channel = client.channels.get(emojiChannelID);
if (!channel) return console.error('Invalid ID or missing channel.');
const messages = await channel.fetchMessages({ limit: 100 });
for (const [id, message] of messages) {
await message.react('✅');
await message.react('✖');
}
} catch(err) {
console.error(err);
}
});
client.on('message', async message => {
if (message.channel.id === emojiChannelID) {
try {
await message.react('✅');
await message.react('✖');
} catch(err) {
console.error(err);
}
}
});
In this code, you'll notice I'm using a for...of loop rather than Map.forEach(). The reasoning behind this is that the latter will simply call the methods and move on. This would cause any rejected promises not to be caught. I've also used async/await style rather than then() chains which could easily get messy.
According to https://discord.js.org/#/docs/main/stable/class/TextChannel
you can use fetchMessages
to get all messages from a specific channel, which then returns a collection of Message
Then you can use .react function to apply your reactions to this collection of message by iterating over it and calling .react on each.
Edit:
channelToFetch.fetchMessages()
.then(messages => {
messages.tap(message => {
message.react(`CHARACTER CODE OR EMOJI CODE`).then(() => {
// Do what ever or use async/await syntax if you don't care
about Promise handling
})
})
})