nyx/events/emoji.js

54 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-06-24 09:53:19 +02:00
const client = require("../bot");
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(":")) {
let 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;
let webhooks = await channel.fetchWebhooks();
let webhook = webhooks.first();
if (webhook === undefined || null || !webhook) {
channel
.createWebhook(client.user.username, {
avatar: client.user.displayAvatarURL(),
})
.then(async webhook => {
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.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;
});