我在编写一个不和谐机器人
我想知道如何在刚刚创建的频道上发送消息
所以我尝试了.then,但它不起作用,所以我不明白为什么:/
我尝试了很多东西,只是访问网络或在YouTube上看视频,但没有人工作
下面是我的代码:
client.on("interactionCreate", async interaction => {
if(interaction.isCommand()){
if(interaction.commandName == "ticket"){
const Embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Do you need help ?')
.setDescription('By clicking on the button,\nModerators will answer your questions/reports!')
.setFooter({ text: 'Created by Skorflex#9141', iconURL: 'https://cdn.discordapp.com/attachments/1082613588507766784/1082613661140537404/logo-transparent.png' });
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('button')
.setLabel('Open a ticket')
.setStyle(ButtonStyle.Primary),
);
await interaction.reply({ embeds: [Embed], components: [row] });
}
}
if(interaction.isButton()){
if(interaction.customId === "button"){
const server = client.guilds.cache.get(guildId);
server.channels.create({name:`ticket-${interaction.user.username}`})
.then(channel => {
let category = client.channels.cache.get(ticket_category);
if (!category) throw new Error("Category channel does not exist");
channel.setParent(category.id);
}).catch(console.error);
interaction.reply({content: "Your ticket is available !", ephemeral: true})
const Embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Thank you for contacting support')
.setDescription('Describe your problem')
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('closebutton')
.setLabel('Close the ticket')
.setStyle(ButtonStyle.Primary),
);
channel.send({embeds:[Embed], row:[row]})
}
}
})
1条答案
按热度按时间ffx8fchx1#
channel
在:因为您在
.then
块之外调用此行。你可以做的是声明一个变量scoped到你的条件。因为你已经使用了
async/await
,你可以使用它来代替.then
,并使用await
解析你的promise:完整片段: