【问题标题】:How do I make a ticketing system for my bot using the discord-buttons npm package?如何使用 discord-buttons npm 包为我的机器人制作票务系统?
【发布时间】:2021-09-10 01:17:50
【问题描述】:

所以我正在为我的 Discord 机器人开发票务系统,我的代码以前可以工作,但我把它搞砸了,现在它不起作用了。

我想要它做什么:当人们点击按钮时(discord-buttons)我希望它首先检查一个名为“Tickets”的类别,然后创建一个名为“(用户名)-ticket”,最后,在刚刚制作的频道中发送嵌入。

实际发生的情况:代码只是说“无法读取未定义的通道”,并且不起作用。

我的代码:

client.on('clickButton', async (button) => {
    if (button.id == "ticket") {
      let embed = new Discord.MessageEmbed;
      embed.setTitle('Created Ticket')
      embed.setDescription('Successfully created your ticket.')
      await button.reply.send({ embed: embed }, true);
      let embed2 = new Discord.MessageEmbed
      embed2.setTitle(`Hello, ${button.clicker.user.username}`)
      embed2.setDescription('Someone will be with you shortly. To close the ticket, press the ❌ emoji.')
      embed2.setFooter('Ticketing System created by FireyJS#6969')
      const guild = button.clicker.guild
if (guild.channels.cache.find(c => c.name.toLowerCase() === 'tickets')) {
  const category = guild.channels.cache.find(c => c.name.toLowerCase() === 'tickets')
 guild.channels.create(`${button.clicker.user.username}-ticket`, { reason : 'Needed to make a ticket lol' }).then(channel => { 
 channel.setParent(category)
 channel.send(embed2)
 }).then(message => { message.react('❌') })
 } else {
   message.channel.send('Make a category named ``Tickets`` to get started with ticketing!')
 }
    }
});

【问题讨论】:

    标签: button discord discord.js discord-buttons


    【解决方案1】:

    button.clicker 对象没有 guild 属性,但 button 本身有。尝试将 guild 定义为 button.guild 而不是您当前拥有的!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-04
      • 2021-02-24
      • 2021-04-25
      • 2017-09-16
      • 2020-07-31
      • 2020-09-27
      • 2023-01-17
      • 2022-12-18
      相关资源
      最近更新 更多