【问题标题】:Ticket System Discord.js v.13票务系统 Discord.js v.13
【发布时间】:2021-12-01 10:18:24
【问题描述】:

我正在尝试编写票务系统脚本。我成功地创建了一张票,但我不知道如何关闭它(删除它)我尝试查找内容,但我找不到我的代码的解决方案。

我的代码:


        case 'ticket':
        case 'Ticket':

            var guild = client.guilds.cache.get('877207084251369512')
            guild.channels.create(message.author.username + '-ticket', {
                type: 'text',
                topic: 'Ticket' + message.author.id,
                parent: '896402801428456046',
                permissionOverwrites: [
                    {
                     id: message.author.id,
                     allow: ['SEND_MESSAGES', 'VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'EMBED_LINKS', 'ATTACH_FILES'],
                    },
                    {
                     id: message.guild.roles.everyone,
                     deny: ['VIEW_CHANNEL'],
                    },
                {
                     id: "877570054710001735",
                     allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                    },
                   ],
                  })

            let created = new Discord.MessageEmbed()
            .setTitle("Ticket-System")
            .setDescription("You're Ticket was created!")
            .setTimestamp()
            .setFooter('Ticket System')
            .setColor("GREY")
            
            
            message.channel.send({embeds: [created]});
            
            let channel = message.guild.channels.cache.find(channel => channel.name === `${message.author.username}-ticket`);
            message.guild.channels.cache.get(`${channel}`)

【问题讨论】:

  • 第一部分是username-ticket,第二部分是ticket-username
  • 提示:如果你将要切换的参数小写,你只需要一个小写的值,而不必担心字母大小写的其他变体

标签: discord discord.js


【解决方案1】:

在这里

guild.channels.create(message.author.username + '-ticket', {

你使用了<someusername>-ticket 并在

.find(channel => channel.name === `ticket-${message.author.username}`);

你用过ticket-<someusername>

要么选择将ticket-<someusername> 放在你的两行中,要么选择<someusername>-ticket

PS:我建议您使用 ID 而不是用户名,因为当用户名可能包含特殊和烦人的字符时,您知道 id 只有数字。 此外,要解决一些潜在问题,您可以将 channel 更改为 channel.id

message.guild.channels.cache.get(`${channel.id}`)

【讨论】:

  • 谢谢我用`ticket-${message.author.username}`改了错误我仍然遇到删除频道的问题
【解决方案2】:

频道名称中会有特殊符号。您可以使用以下程序删除特殊符号和空格

const channelname1 = removeSpaces(`${message.author.username}`)
const channelname = channelname1.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');

删除频道 那我不知道你想怎么删除频道,我只能给你一个删除频道的方法

channel.delete();

另外,我建议你在定义频道的时候可以延迟0.5秒

【讨论】:

  • 我试图像这样删除频道,你可以看到我的代码 here 但它不起作用
猜你喜欢
  • 1970-01-01
  • 2020-11-24
  • 2021-11-28
  • 1970-01-01
  • 2021-04-04
  • 1970-01-01
  • 2011-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多