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. Now I wanna do something that they just have to write "delete", without any channelid or name and the channel should get deleted. 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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.