gpt4 book ai didi

javascript - Discord.js 删除消息功能的问题

转载 作者:行者123 更新时间:2023-12-02 23:25:19 25 4
gpt4 key购买 nike

我在使用 Discord.js 删除功能时遇到一些问题。当从 channel 中删除图像时,我使用此代码从用户的余额中删除 1 点,第一次一切正常,但是当我尝试删除我发送的另一张图像时,而不是从我的余额中删除 1 点,机器人将删除许多点,因为从机器人启动开始,总共删除了多少图像。示例:我删除一张图像,机器人将从我的余额中删除 1 点,然后如果我删除上传的另一张图像,它不会删除 1 点,而是从我的余额中删除 2 点,因为它会计算删除的第一张图像和这个。我该如何修复它并只响应删除的一张图像?

//(works) This is the function that make the bot read the message's attach
function attachIsImageJPG(messageAttach) {
var url = messageAttach.url;
//True if this url is a png image.
return url.indexOf("jpg", url.length - "jpg".length /*or 3*/) !== -1;
}

//(works) There's the code that make the bot assign 1 point when the image is uploaded
if (message.attachments.size > 0) {
if (message.channel.id != '593093789971644417') return;
if (message.attachments.every(attachIsImage)){
eco.AddToBalance(message.author.id, 1)
bot.channels.get("593093471175311438").send(itag + message.author.id + ftag + " **1** has been **added** to your `!balance` for sending the success the screenshot");
}
}

//(problem) This is the part with the error
bot.on("messageDelete", async (messageDelete) => {
if (messageDelete.channel.id === '593093789971644417') {

function attachIsImageJPG(messageAttach) {
var url = messageAttach.url;
//True if this url is a png image.
return url.indexOf("jpg", url.length - "jpg".length /*or 3*/) !== -1;
}
if (message.attachments.size > 0) {
if (message.attachments.every(attachIsImageJPG)) {
await eco.SubstractFromBalance(message.author.id, 1) // money.updateBal grabs the (userID, value) value being how much you want to add, and puts it into 'i'.
return bot.channels.get("593093471175311438").send(itag + message.author.id + ftag + " **1** has been **removed** from your `!balance` for deleting the screenshot");
} else return;
} else return;
} else return;
});

机器人应该只从用户的余额中扣除 1 点。

最佳答案

我的问题是我在 message 事件中发生了 messageDelete 事件。 attachIsImage() 应该在任何事件外部定义,然后在事件内部调用。

关于javascript - Discord.js 删除消息功能的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56759165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com