Edit channel topic with simple command and add animated and emoji from diffrent servers in it without Nitro. To use emoji in topic type :emoji-name: in slash command option. Note there are too often ratelimit. Slash command structure : https://i.imgur.com/fRptdfD.png. What is does : https://imgur.com/a/P9Jr2ib
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
await lib.discord.interactions['@1.0.1'].responses.ephemeral.create({
token: `${context.params.event.token}`,
response_type: 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE'
});
if (!context.params.event.member.permission_names.includes('MANAGE_CHANNELS')) {
await lib.discord.interactions['@1.0.1'].responses.update({
token: `${context.params.event.token}`,
content: `Uh! You dont have \`MANAGE_CHANNELS\` Permission!`,
});
return;
}
try{
let channel = context.params.event.data.options[0].value;
let topic = context.params.event.data.options[1].value;
let emojis = topic.match(/(?<=:)([^:\s]+)(?=:)/g);
let guilds = await lib.discord.guilds['@0.1.0'].list({
limit: 200,
});
let all_emojis = await lib.discord.guilds['@0.1.0'].emojis.list({
guild_id: guilds[0].id,
});
for (let i = 1; i < guilds.length; i++) {
let guild_emojis = await lib.discord.guilds['@0.1.0'].emojis.list({
guild_id: guilds[i].id,
});
all_emojis = all_emojis.concat(guild_emojis);
}
if (!emojis){
await lib.discord.channels['@0.2.0'].update({
channel_id: channel,
topic: topic,
});
await lib.discord.interactions['@1.0.1'].responses.update({
token: `${context.params.event.token}`,
content: `Updated <#${channel}>'s topic to : \n${topic}`,
});
return;
} else{
emojis.forEach((e) => {
let emoji = all_emojis.find((E) => E.name === e);
emoji = `<${emoji.animated ? 'a' : ''}:${emoji.name}:${emoji.id}>`;
if (new RegExp(emoji, 'g').test(topic)) {
topic = topic.replace(new RegExp(emoji, 'g'), emoji);
} else topic = topic.replace(new RegExp(':' + e + ':', 'g'), emoji);
});
await lib.discord.channels['@0.2.0'].update({
channel_id: channel,
topic: topic ,
});
await lib.discord.interactions['@1.0.1'].responses.update({
token: `${context.params.event.token}`,
content: `Updated <#${channel}>'s topic to : \n${topic}`,
});
}
} catch (e) {
console.log(e)
await lib.discord.interactions['@1.0.1'].responses.update({
token: `${context.params.event.token}`,
content: `Uh! an error occurred! \nMake sure topic provided wasn't too big and Bot has required Permissios! \n If you have make sure this is neither of reasons for error then it's bot which is getting rateLimited`,
});
}