Professional Documents
Culture Documents
Afkcmd Js
Afkcmd Js
module.exports = {
data: new SlashCommandBuilder()
.setName('afk')
.setDescription('Going AFK? Let others know!')
.addStringOption((opt)=>opt.setName('reason').setDescription('The reason
why you\'re going AFK.')),
async execute(interaction){
await interaction.deferReply()
var reason
if(interaction.options.getString('reason') === null){
reason = "No reason specified."
} else{reason = interaction.options.getString('reason')}
if(reason.length > 1024){
return await interaction.editReply(script.sendFail('Your `reason`
has over 1024 characters. I can\'t digest them all!'))
}
const time = Math.round(new Date().getTime()/1000) // To get the UNIX
timestamp
const database = await script.connectDb('AFK')
const data = await database.findOne({'_id':interaction.user.id})
var embed = new MessageEmbed()
.setTitle('💤 AFK Set!')
.setFooter("If other members mention you, I'll let them know that
you're AFK!")
.setColor(interaction.member.displayHexColor)
.setThumbnail(script.avatar(interaction.user))
if(data === null || data === undefined){
await database.insertOne({'_id':interaction.user.id,
'guildId':interaction.guild.id, 'reason': reason, 'time': time})
embed
.setDescription(`User: ${interaction.user.tag}\n`+`Reason: $
{reason}`)
}else{
await database.findOneAndUpdate({'_id': interaction.user.id,
'guildId':interaction.guild.id}, {'$set':{'reason': reason, 'time': time}})
embed
.setDescription(`User: ${interaction.user.tag}\n`+`Reason: $
{reason}`)
}
await interaction.editReply({embeds:[embed]})
}
}