简体   繁体   English

如何删除消息不是频道 discord.js

[英]how to delete a message not a channel discord.js

I have tried looking for how to delete a message by id and I get the id by getting the channel and going through the json object and take the last message id and want to delete it but when I run it just deletes the entire channel我尝试寻找如何通过 id 删除消息,我通过获取频道并通过 json object 并获取最后一个消息 id 并想要删除它,但是当我运行它时,它只会删除整个频道

This is what I have for the code这就是我的代码

let x = client.channels.cache.get('830341462070919168')
let lastMessageID = x.lastMessageID;

client.channels.cache.get('830341462070919168').fetch(lastMessageID).then(msg => msg.delete());

client.channels.cache.get('830341462070919168').send('**UPDATE!!**\nList of Photo Shoots to be done\n```1. Nick\n2. Drew```');

And I saw on another form that I could try this我在另一个表格上看到我可以试试这个

client.channels.cache.get('830341462070919168').fetch(lastMessageID).then(async msg => {
    await client.channels.cache.get('830341462070919168').send("**UPDATE!!**\nList of Photo Shoots to be done\n```1. Nick\n2. Drew```");
    if (msg) msg.delete();
});

And it does the same thing as what I have above它和我上面做的一样

All I want it to do is just get the last message id and delete that message by the id and nothing else and then update with a new message that I will have loop through all the sign ups and then put that into a message我想要它做的只是获取最后一条消息 id 并通过 id 删除该消息,然后使用一条新消息进行更新,我将循环遍历所有注册,然后将其放入消息中

output: UPDATE!! output:更新!! Lise of Photo Shoots to be done Lise of Photo Shoots to be done

1. {name}
2. {name}
etc..

I fixed it all I needed to do was to put the id inside the delete function我修复了它,我需要做的就是将 id 放入删除 function

Example:例子:

client.channels.cache.get('830342527340773386').messages.delete(lastMessageID);

In your case, client.channels.cache.get('830341462070919168').fetch(lastMessageID) would return the channel itself.在您的情况下, client.channels.cache.get('830341462070919168').fetch(lastMessageID)将返回频道本身。 So calling Channel.delete() would delete the channel.所以调用Channel.delete()会删除频道。 So you can either do like what you have answered, or do client.channels.cache.get('830341462070919168').message.fetch(lastMessageID) to get the message and then resolve the promise to delete the message.所以你可以像你回答的那样做,或者做client.channels.cache.get('830341462070919168').message.fetch(lastMessageID)来获取消息,然后解析 promise 来删除消息。 <MessageManager>#fetch() <消息管理器>#fetch()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM