简体   繁体   English

从机器人中删除 discord dm

[英]Delete a discord dm from a bot

so my question is how i can delete a message sent by a bot thats sends dc invites to users.所以我的问题是如何删除由向用户发送 dc 邀请的机器人发送的消息。 Here is my code:这是我的代码:

                        await reaction.message.guild.members.cache
                          .get(user.id);
                          if(array.length >= 1){
                          if(message.member.roles.cache.has('529770658914369537')){
                            const channel = client.channels.cache.find(channel => channel.name === 'Gaming Lounge')
                            let invite = await channel.createInvite({
                              maxAge: 60000, 
                              maxUses: 1 
                            }).catch(console.error);
                            client.users.cache.get(array[0]).send(`Here is your Invite: ${invite}`);
                            array.splice(0, 1);
                            console.log(array);
                            reaction.users.remove(user);

Looking at the documentation you can get a rough idea.查看文档,您可以大致了解一下。 essentially you send the message and store the resolved promise (use await) into a variable.本质上,您发送消息并将解析的 promise(使用等待)存储到变量中。 this variable contains the delete method which is pretty self explanatory这个变量包含删除方法,这很不言自明


if (command === "king") {
    const DELAY = 5000 // delay before deleting message
    const kingMessage = await message.channel.send("test");
    kingMessage.delete({ timeout: DELAY })
}

Link to documentation for delete method: https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=delete链接到删除方法的文档: https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=delete

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

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