[英]DJS v14 How to count every embed message it's been sent?
I would like to make it count on every embed sent to a text channel with +1?我想让它依赖于发送到 +1 文本频道的每个嵌入? For example a user writes to a text channel.
例如,用户写入文本通道。 BOT is gonna take that message, delete it and post it by tagging him and count the embed as number #1 etc.. Thanks in advance!!
BOT 将接收该消息,将其删除并通过标记他发布并将嵌入计数为 #1 等。在此先感谢!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const v10_1 = require("discord-api-types/v10");
const discord_js_1 = require("discord.js");
const Events_1 = require("../../structures/Events");
exports.default = new Events_1.Event("messageCreate", async (message) => {
try {
if (message.author.bot)
return;
if (message.channelId !== process.env.reviewsChannelId)
return;
if (message.channel.type !== v10_1.ChannelType.GuildNewsThread &&
message.channel.type !== v10_1.ChannelType.GuildText)
return;
const content = message?.content;
if (!content)
return await message.delete();
const reviews = new discord_js_1.EmbedBuilder()
.setTitle(`[ <:review:1005784096120782888> ] - Review - [ <:review:1005784096120782888> ]`)
.setColor(`#fdaf17`)
.setDescription(`**${content}**`)
.setTimestamp();
await message.channel.send({ embeds: [reviews] });
await message.delete();
}
catch (error) {
return console.log(error);
}
});
you have 2 choices, a simple variable like你有 2 个选择,一个简单的变量,比如
let count = 1;
and after each await message.channel.send({ embeds: [reviews] });
并在每次
await message.channel.send({ embeds: [reviews] });
you add a line with count++;
你用
count++;
and in the embed you write by example .setFooter({text: "Embed #" + count})
并在您通过示例编写的嵌入中
.setFooter({text: "Embed #" + count})
But the problem of this solution is if your bot restart, you'll loose the actual embed count.但是这个解决方案的问题是,如果你的机器人重新启动,你会失去实际的嵌入计数。
So you can do the same way but instead of a simple variable, use a json file to store the variable or a database.因此,您可以使用相同的方式,但不是使用简单的变量,而是使用 json 文件来存储变量或数据库。
Hope this can helps you !希望这可以帮助你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.