[英]Discord.js is it possible to delete a channel only with “close” (without channeID)?
Hey I'm working on a small answer bot.嘿,我正在开发一个小型回答机器人。 My members can open tickets/channels with an already existing discord bot and in these tickets they write with my bot.
我的成员可以使用已经存在的 discord 机器人打开票证/频道,并在这些票证中使用我的机器人编写。 Now I wanna do something that they just have to write "delete", without any channelid or name and the channel should get deleted.
现在我想做一些他们只需要写“删除”的事情,没有任何频道 ID 或名称,频道应该被删除。 I searched for it, but all I found wasn't exactly what I wanted.
我搜索了它,但我发现的并不是我想要的。 I tried a little bit around but I just get errors.
我尝试了一下,但我只是得到了错误。
This is the code:这是代码:
const client = new Discord.Client();
const config = require("./config.json");
const prefix = require('discord-prefix');
client.on("ready", () => {
console.log("I am ready!");
});
//if the server doesn't have a set prefix yet
let defaultPrefix = '.';
client.on('message', (message) => {
if (!message.guild) return;
//get the prefix for the discord server
let guildPrefix = prefix.getPrefix(message.guild.id);
if (!guildPrefix) guildPrefix = defaultPrefix;
let args = message.content.slice(guildPrefix.length).split(' ');
if (!message.content.startsWith(guildPrefix)) return;
if (args[0].toLowerCase() === ('ping')) {
const user = message.author.name;
return message.reply('pong');
} else
if (args[0].toLowerCase() === ('close') || args[0].toLowerCase() === ('delete') || args[0].toLowerCase() === ('cancel')) {
const channel = message.guild.channels.find(channel => channel.name === name)
channel.delete('Deleting the channel')
.then(deleted => console.log(`Deleted ${deleted.name}`))
.catch(console.error);
};
});
Thanks for any help!谢谢你的帮助!
You could give the Channel a special name.你可以给频道一个特殊的名字。 For example
MEMBERSID-TICKET
and after the User uses the CMD it searches for a channel that includes the Members ID
and TICKET
.例如
MEMBERSID-TICKET
,在用户使用 CMD 后,它会搜索包含Members ID
和TICKET
的频道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.