Reputation: 111
I'm creating a logging system for my Discord server of over 12k members. What I would like to achieve is that whenever a moderator uses the .lock command, the bot sends a message to the logs channel and DM's me. Both work, but I can't figure out how to attach the message url so that I can click on that and immediately jump to the .lock command itself so I can review what happened.
This is the code that I have thus far:
// Message url to be used in logging later.
const msgURL = 'empty';
// Send lock message
const embed = new Discord.MessageEmbed()
.setTitle("LOCKDOWN")
.setColor('#ff0000')
.setDescription("There have been a large number of infringements in this channel. Please be patient as we review the sent messages and take appropriate action.")
.setFooter("Please do not DM staff asking when the lockdown will be over. ");
message.channel.send({embed}).then(msgURL => {
msgURL = embed.url;
})
// Send unlock notification to #staff-logs.
// async method to get the channel id (in case of delay.)
function getStaffLogChannel(){
return message.guild.channels.cache.get('ID');
}
// Staff logs channel
let staffLogs = await getStaffLogChannel();
// User who issued the command
let commandIssuer = message.member.user.tag;
// message published in staff-logs
staffLogs.send(commandIssuer + " has used the **.lock** command in: " + message.channel.name)
// send notification in DM
client.users.cache.get('ID').send(commandIssuer + " has used the **.lock** command in: " + message.channel.name + " ( " + msgURL + " )");
I have also tried to change the
message.channel.send({embed}).then(msgURL => {
msgURL = embed.url;
})
to:
message.channel.send({embed}).then(msgURL => {
msgURL = embed.url.get;
})
But that unfortunately doesn't work either. Here you get this error:
TypeError: Cannot read property 'get' of null`
Upvotes: 1
Views: 2286
Reputation: 1227
You can just use Message#url. There is no need for the .get()
.
You are trying to get the URL of the embed, not the message.
Upvotes: 1