gpt4 book ai didi

javascript - 工单命令 : DiscordAPIError: Interaction has already been acknowledged

转载 作者:行者123 更新时间:2023-12-05 04:26:36 34 4
gpt4 key购买 nike

我知道这个问题已经有人问过,但我找不到好的答案。每当我点击我制作的按钮时,一切似乎都正常,但我创建了多个 channel 。它应该只做一个。然后我得到这个错误。

代码:

else if (interaction.isButton()) {
if (interaction.customId === "ticket") {
var categoryId = "998616644123381913"
var userName = interaction.user.username
var userDiscrimator = interaction.user.discriminator
var ticketExist = false;
interaction.guild.channels.cache.forEach((channel) => {
if(channel.name == userName.toLocaleLowerCase() + "#" + userDiscrimator){
let ticketEmbed = new MessageEmbed()
.setTitle("You already have an Ticket Open!")
.setColor("RED")
.setDescription("Please talk in that ticket!")
interaction.reply({embeds: ticketEmbed, ephemeral: true })
ticketExist = true;
return;
}
if(ticketExist) return;
interaction.guild.channels.create(userName.toLocaleLowerCase() + "#" + userDiscrimator).then((createdChen) =>{
createdChen.setParent(categoryId).then((settedParent) =>{

settedParent.permissionOverwrites.edit(interaction.guild.roles.cache.find(x => x.name === "@everyone"), {

SEND_MESSAGES: false,
VIEW_CHANNEL: false

});


settedParent.permissionOverwrites.edit(interaction.user.id, {
CREATE_INSTANT_INVITE: false,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
ATTACH_FILES: true,
CONNECT: true,
ADD_REACTIONS: true
});


settedParent.permissionOverwrites.edit(interaction.guild.roles.cache.find(x => x.name === "member"), {
CREATE_INSTANT_INVITE: false,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
ATTACH_FILES: true,
CONNECT: true,
ADD_REACTIONS: true
});

let today = new Date();
let dd = String(today.getDate()).padStart(2, '0');
let mm = String(today.getMonth() + 1).padStart(2, '0');
let yyyy = today.getFullYear();
today = `${dd}/${mm}/${yyyy}`;

let embedParent = new MessageEmbed()
.setAuthor(interaction.user.tag, interaction.user.displayAvatarURL({ dynamic: true }))
.setTitle("New Ticket!")
.addFields(
{ name: "Created by:", value: interaction.user.username, inline: true },
{ name: "Made on ", value: today, inline: true }
)
let embed21 = new MessageEmbed()
.setTitle("✅Ticket created")
interaction.reply({ embeds: [embed21], ephemeral: true })
settedParent.send({ embeds: [embedParent] })
}).catch(err => {
let errEmbed = new MessageEmbed()
.setTitle("Something went wrong")
.setColor("RED")
interaction.reply({embeds: errEmbed, ephemeral: true })
console.log(err)
})

}).catch(err => {
let errEmbed2 = new MessageEmbed()
.setTitle("Something went wrong")
.setColor("RED")
interaction.reply({ embeds: {errEmbed2}, ephemeral: true })
console.log(err)
})
})
}
}

错误:

DiscordAPIError: Interaction has already been acknowledged.
at RequestHandler.execute (C:\Users\stixy\Desktop\v-13\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\stixy\Desktop\v-13\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async ButtonInteraction.reply (C:\Users\stixy\Desktop\v-13\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:103:5) {
method: 'post',
path: '/interactions/998629381398347907/aW50ZXJhY3Rpb246OTk4NjI5MzgxMzk4MzQ3OTA3OlE4ZHdmc3VtaHZ2cWRUMXdMemFPTlFyOW1hT0pzY003S1hrcVI4a2p2ZlBucnRCNFhCSW11NWV0b29NM1lpcTFzdFVpekQyTTFuYlJteHRHZjJzZzRVVjBBNkI5T003Sk5YWG1kQ1FUb0xJZnE4bUhLUENXTVc2T0dpYnJLckpR/callback',
code: 40060,
httpStatus: 400,
requestData: {
json: {
type: 4,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: '✅Ticket created',
type: 'rich',
description: null,
url: null,
timestamp: 0,
color: null,
fields: [],
thumbnail: null,
image: null,
author: null,
footer: null
}
],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 64,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
}
},
files: []
}
}

最佳答案

使用 interaction.guild.channels.cache.forEach,您可以创建与当时一样多的新 channel 。而且您还尝试以这种方式发送多个回复,导致错误。

如果你想检查是否存在具有特定名称的 channel ,你可以使用 channels.cache.find() 并提供一个回调,你可以在其中检查项目/ channel 名称是否是一样。

您的代码中还有其他错误,例如您试图将嵌入作为单个嵌入而不是数组发送。您也可以使用 interaction.guild.id 而不是查找 @everyone Angular 色。您可以使用的另一件事是 new Date().toLocaleDateString('en-GB') 而不是今天日期的自定义按摩。

对您的代码进行了一些更改,使其更易于阅读:

// ..
if (interaction.isButton()) {
if (interaction.customId !== 'ticket') return;

const categoryId = '998616644123381913';
const userName = interaction.user.username;
const userDiscrimator = interaction.user.discriminator;
const ticketChannelName = `${userName.toLocaleLowerCase()}#${userDiscrimator}`;
const ticketExist = interaction.guild.channels.cache.find(
(ch) => ch.name === ticketChannelName
);

if (ticketExist)
return interaction.reply({
embeds: [
new MessageEmbed()
.setTitle('You already have an Ticket Open!')
.setColor('RED')
.setDescription('Please talk in that ticket!'),
],
ephemeral: true,
});

try {
let createdChannel = await interaction.guild.channels.create(ticketChannelName);
await createdChannel.setParent(categoryId);

createdChannel.permissionOverwrites.edit(interaction.guild.id, {
SEND_MESSAGES: false,
VIEW_CHANNEL: false,
});

createdChannel.permissionOverwrites.edit(interaction.user.id, {
CREATE_INSTANT_INVITE: false,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
ATTACH_FILES: true,
CONNECT: true,
ADD_REACTIONS: true,
});
// do you really need this?
createdChannel.permissionOverwrites.edit(
interaction.guild.roles.cache.find((x) => x.name === 'member'),
{
CREATE_INSTANT_INVITE: false,
READ_MESSAGE_HISTORY: true,
SEND_MESSAGES: true,
ATTACH_FILES: true,
CONNECT: true,
ADD_REACTIONS: true,
},
);

let ticketEmbed = new MessageEmbed()
.setAuthor(
interaction.user.tag,
interaction.user.displayAvatarURL({ dynamic: true }),
)
.setTitle('New Ticket!')
.addFields(
{
name: 'Created by:',
value: interaction.user.username,
inline: true,
},
{
name: 'Made on ',
value: new Date().toLocaleDateString('en-GB'),
inline: true,
},
);

interaction.reply({
embeds: [new MessageEmbed().setTitle('✅Ticket created')],
ephemeral: true,
});
createdChannel.send({ embeds: [ticketEmbed] });
} catch (err) {
interaction.reply({
embeds: [
new MessageEmbed().setTitle('Something went wrong').setColor('RED'),
],
ephemeral: true,
});
console.log(err);
}
}
// ...

关于javascript - 工单命令 : DiscordAPIError: Interaction has already been acknowledged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73025902/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com