This snippet allows users of your server to set their own prefix + their own command response! It includes help command (!customhelp - as default prefix) so you don't get lost! Enjoy :)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let message = context.params.event.content;
let newtext = context.params.event.content.split(' ').slice(1).join(' ');
let customprefix = await lib.utils.kv['@0.1.16'].get({
key: `customone-${context.params.event.author.id}`,
defaultValue: `!`, //default prefix - can be changed
});
let customtext = await lib.utils.kv['@0.1.16'].get({
key: `customtext-${context.params.event.author.id}`,
defaultValue: `Use **${customprefix}textset** to change this text!`, //default text for the command's response - can be changed
});
if (message.toLowerCase().startsWith(`${customprefix}customcommand`)) {
await lib.discord.channels[`@0.1.1`].messages.create({
channel_id: context.params.event.channel_id,
content: `${customtext}`,
});
}
if (message.toLowerCase().startsWith(`${customprefix}textset`)) {
if (newtext) {
await lib.utils.kv['@0.1.16'].set({
key: `customtext-${context.params.event.author.id}`,
value: `${newtext}`,
});
await lib.discord.channels[`@0.1.1`].messages.create({
channel_id: context.params.event.channel_id,
content: `Succesfully set <@${context.params.event.author.id}>'s custom command text to **${newtext}** - to actually see this command in action, use **${customprefix}customcommand**`,
});
} else {
await lib.discord.channels[`@0.1.1`].messages.create({
channel_id: context.params.event.channel_id,
content: `<@${context.params.event.author.id}> you need to provide something! Example: **${customprefix}textset Test** - use **${customprefix}customcommand** for actual custom command!`,
});
}
}
if (message.toLowerCase().startsWith(`!changemyprefix`)) {
if (newtext) {
await lib.utils.kv['@0.1.16'].set({
key: `customone-${context.params.event.author.id}`,
value: `${newtext}`,
});
await lib.discord.channels[`@0.1.1`].messages.create({
channel_id: context.params.event.channel_id,
content: `Succesfully set <@${context.params.event.author.id}>'s custom command prefix to **${newtext}**`,
});
} else {
await lib.discord.channels[`@0.1.1`].messages.create({
channel_id: context.params.event.channel_id,
content: `<@${context.params.event.author.id}> provide your new prefix please! Example: **!changemyprefix ?** - to check your current prefix use **!myprefix**`,
});
}
}
if (message.toLowerCase().startsWith(`${customprefix}customhelp`)) {
await lib.discord.channels[`@0.1.1`].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
embed: {
title: `Custom Commands Help List:`,
color: 0x00FF00,
fields: [
{
name: `How to set your prefix?`,
value: `Use: **!changemyprefix **`,
},
{
name: `How to set what my command is gonna send?`,
value: `Use: **${customprefix}textset **`,
},
{
name: `How to even use Custom Command?`,
value: `Nice question, use **${customprefix}customcommand**`,
},
{
name: `How to check what prefix do you have at the moment?`,
value: `Use: **!myprefix**`,
},
],
},
});
}
if (message.toLowerCase() === `!myprefix`) {
await lib.discord.channels[`@0.1.1`].messages.create({
channel_id: context.params.event.channel_id,
content: `<@${context.params.event.author.id}>'s prefix is **${customprefix}**`,
});
}