Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

javascript - Discord.js - Bot won't specify/mention the channel in logs

When attempting to create a "purge" command, I wish to make it delete messages, as well as log the action within a specified log channel. However, the log won't specify the channel the command was executed within, and I am unsure how to make it mention the channel.

This is what I have:

if (command === 'purge') {
  if (
    !message.member.roles.cache.some((r) => ['Indian Mod'].includes(r.name))
  )
    return message.reply('not high enough perms ``(MOD PERMS)``');
  let member = message.mentions.members.first();
  const channel11 = client.channels.cache.find(
    (channel) => channel.id === 'id',
  );
  const deleteCount = parseInt(args[0], 10);
  if (!deleteCount || deleteCount < 2 || deleteCount > 100)
    return message.reply(
      'Please provide a number between 2 and 100 for the number of messages to delete',
    );
  channel = message.guild.channels.cache.get('channelID');
  const fetched = await message.channel.messages.fetch({
    limit: deleteCount,
  });
  message.channel
    .bulkDelete(fetched)
    .catch((error) =>
      message.reply(`Couldn't delete messages because of: ${error}`),
    );
  const embedmessagep = new Discord.MessageEmbed()
    .setColor(`RANDOM`)
    .setTitle('Purge Command Executed')
    .setTimestamp()
    .setFooter('DM me with any inquiries regarding bot API')
    .addFields(
      { name: `Channel:`, value: `<#${message.guild.id}>` },
      { name: `Moderator:`, value: `${message.author.tag}` },
      { name: `Number Deleted:`, value: `${deleteCount}` },
    );
  channel11.send(embedmessagep);
}

The line in which the issue occurs is within the embed:

{ name: `Channel:`, value: `<#${message.guild.id}>` },
question from:https://stackoverflow.com/questions/66052814/discord-js-bot-wont-specify-mention-the-channel-in-logs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

message.guild.id is the server ID, not the channel ID. Did you mean message.channel.id?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...