nyx/events/emoji.js

60 lines
2 KiB
JavaScript
Raw Normal View History

const client = require("../");
2021-09-06 12:38:25 +02:00
client.on("messageCreate", async message => {
2021-06-12 12:53:51 +02:00
function Check(str) {
if (
client.emojis.cache.find(emoji => emoji.name === str) ||
message.guild.emojis.cache.find(emoji => emoji.name === str)
) {
2021-06-12 12:53:51 +02:00
return true;
} else {
return false;
}
2021-06-12 12:53:51 +02:00
}
if (message.content.startsWith(":") && message.content.endsWith(":")) {
const EmojiName = message.content.slice(1, -1);
2021-06-24 09:53:19 +02:00
if (client.path.includes(message.guild.id)) return;
2021-06-12 12:53:51 +02:00
if (Check(EmojiName) === true) {
const channel = client.channels.cache.get(message.channel.id);
try {
if (message.author.bot) return;
const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.first();
2021-06-12 12:53:51 +02:00
if (webhook === undefined || null || !webhook) {
channel
.createWebhook(client.user.username, {
avatar: client.user.displayAvatarURL(),
})
.then(async w => {
2021-06-12 12:53:51 +02:00
const emoji =
client.emojis.cache.find(e => e.name == EmojiName).id ||
message.guild.emojis.cache.find(e => e.name === EmojiName).id;
await w.send(`${client.emojis.cache.get(emoji)}`, {
2021-06-12 12:53:51 +02:00
username: message.member.displayName
? message.member.displayName
: message.author.username,
avatarURL: message.author.displayAvatarURL({ dynamic: true }),
});
message.delete();
});
}
const emoji =
client.emojis.cache.find(e => e.name == EmojiName).id ||
message.guild.emojis.cache.find(e => e.name === EmojiName).id;
await webhook.send(`${client.emojis.cache.get(emoji)}`, {
username: message.author.username,
avatarURL: message.author.displayAvatarURL({ dynamic: true }),
});
message.delete();
2021-06-24 09:53:19 +02:00
} catch (e) {
console.log(e);
2021-06-12 12:53:51 +02:00
}
} else {
return;
}
} else {
return;
}
2021-06-12 12:53:51 +02:00
});