如何让我的自定义 discord 机器人在发送消息后几秒钟内删除它发送的嵌入
How do I make my custom discord bot to delete an embed it sent out in a few seconds after the msg has been sent
我希望我的机器人删除它在有人使用脏话时发出的嵌入。我希望它在 5-6 秒内删除嵌入需要 5 或 6,所以它在该区域占用更少 space。
const Discord = require('discord.js');
const { Client, MessageEmbed } = require('discord.js');
const bot = new Client();
const token = 'tokenhere';
bot.on('ready', () =>{
bot.user.setActivity('YOU', { type: 'WATCHING' });
console.log('This bot is online!');
});
bot.on('message', message=>{
const user = message.author;
const swearWords = ["fuck", "dick", "pussy", "vagina", "bsdk", "saale", "kutte", "bitch", "die", "mf", "bish", "fag","ass","nigga","nigger","fack"];
if (swearWords.some(word => message.content.toLowerCase().includes(word)) ) {
const embed = new MessageEmbed()
.setTitle('Chat F!lter')
.setColor(0xff0000)
.setDescription('<@' + message.author.id + '> You have been caught being toxic! , You are muted for a minute');
message.channel.send(embed);
const role = message.guild.roles.cache.find(x => x.name == 'muted');
message.member.roles.add(role);
setTimeout(() => {message.member.roles.remove(role)}, 60*1000);
}});
bot.login(token);
message.channel.send()
returns 一个承诺,你可以解决这个承诺,然后使用 <message>.delete({ timeout: 'time-goes-here' })
方法,所以你的代码看起来像这样。
const Discord = require('discord.js');
const { Client, MessageEmbed } = require('discord.js');
const bot = new Client();
const token = 'token-goes-here';
bot.on('ready', () =>{
bot.user.setActivity('YOU', { type: 'WATCHING' });
console.log('This bot is online!');
});
bot.on('message', message=>{
const user = message.author;
const swearWords = ["fuck", "dick", "pussy", "vagina", "bsdk", "saale", "kutte", "bitch", "die", "mf", "bish", "fag","ass","nigga","nigger","fack"];
if (swearWords.some(word => message.content.toLowerCase().includes(word)) ) {
const embed = new MessageEmbed()
.setTitle('Chat F!lter')
.setColor(0xff0000)
.setDescription('<@' + message.author.id + '> You have been caught being toxic! , You are muted for a minute');
// send and deleting the embed
message.channel.send(embed).then(msg => msg.delete({ timeout: 5000 })); // delete embed after 5 seconds (5000 ms)
const role = message.guild.roles.cache.find(x => x.name == 'muted');
message.member.roles.add(role);
setTimeout(() => {message.member.roles.remove(role)}, 60*1000);
}});
bot.login(token);
我希望我的机器人删除它在有人使用脏话时发出的嵌入。我希望它在 5-6 秒内删除嵌入需要 5 或 6,所以它在该区域占用更少 space。
const Discord = require('discord.js');
const { Client, MessageEmbed } = require('discord.js');
const bot = new Client();
const token = 'tokenhere';
bot.on('ready', () =>{
bot.user.setActivity('YOU', { type: 'WATCHING' });
console.log('This bot is online!');
});
bot.on('message', message=>{
const user = message.author;
const swearWords = ["fuck", "dick", "pussy", "vagina", "bsdk", "saale", "kutte", "bitch", "die", "mf", "bish", "fag","ass","nigga","nigger","fack"];
if (swearWords.some(word => message.content.toLowerCase().includes(word)) ) {
const embed = new MessageEmbed()
.setTitle('Chat F!lter')
.setColor(0xff0000)
.setDescription('<@' + message.author.id + '> You have been caught being toxic! , You are muted for a minute');
message.channel.send(embed);
const role = message.guild.roles.cache.find(x => x.name == 'muted');
message.member.roles.add(role);
setTimeout(() => {message.member.roles.remove(role)}, 60*1000);
}});
bot.login(token);
message.channel.send()
returns 一个承诺,你可以解决这个承诺,然后使用 <message>.delete({ timeout: 'time-goes-here' })
方法,所以你的代码看起来像这样。
const Discord = require('discord.js');
const { Client, MessageEmbed } = require('discord.js');
const bot = new Client();
const token = 'token-goes-here';
bot.on('ready', () =>{
bot.user.setActivity('YOU', { type: 'WATCHING' });
console.log('This bot is online!');
});
bot.on('message', message=>{
const user = message.author;
const swearWords = ["fuck", "dick", "pussy", "vagina", "bsdk", "saale", "kutte", "bitch", "die", "mf", "bish", "fag","ass","nigga","nigger","fack"];
if (swearWords.some(word => message.content.toLowerCase().includes(word)) ) {
const embed = new MessageEmbed()
.setTitle('Chat F!lter')
.setColor(0xff0000)
.setDescription('<@' + message.author.id + '> You have been caught being toxic! , You are muted for a minute');
// send and deleting the embed
message.channel.send(embed).then(msg => msg.delete({ timeout: 5000 })); // delete embed after 5 seconds (5000 ms)
const role = message.guild.roles.cache.find(x => x.name == 'muted');
message.member.roles.add(role);
setTimeout(() => {message.member.roles.remove(role)}, 60*1000);
}});
bot.login(token);