discord.js | Bot 没有标记我的频道(未定义)
discord.js | Bot doesn't tag my channel(undefined)
我为我的 discord 机器人发出了 purge/clear 命令,但是当我执行 /purge amount: (amount) 时,它工作正常,但机器人回复 ️ (amount) messages were deleted from undefined.
,应该是 ️ (amount) messages were deleted from #moderator-only.
。这是因为我没有正确的意图还是我做错了什么?我目前只有 SERVER MEMBERS
意图。
代码:
const { CommandInteraction, MessageEmbed } = require('discord.js');
module.exports = {
name: "purge",
description: "Deletes a specific amount of messages from a target.",
permissions: "MANAGE_MESSAGES",
options: [
{
name: "amount",
description: "Select the amount of messages to remove from the target.",
type: "NUMBER",
required: true
},
{
name: "target",
description: "Select the target to remove messages from.",
type: "USER",
required: false
}
],
/**
* @param {CommandInteraction} interaction
*/
async execute(interaction) {
const { channel, options } = interaction;
const Amount = options.getNumber("amount");
const Target = options.getMember("target");
const Messages = await channel.messages.fetch();
const Response = new MessageEmbed()
.setColor('#171717');
if(Target) {
let i = 0;
const filtered = [];
(await Messages).filter((m) => {
if(m.author.id === Target.id && Amount > i) {
filtered.push(m);
i++;
}
})
await channel.bulkDelete(filtered, true).then(messages => {
Response.setDescription(`️ **${messages.size}** messages were deleted from ${Target}.`);
interaction.reply({embeds: [Response]});
})
} else {
await channel.bulkDelete(Amount, true).then(messages =>{
Response.setDescription(`️ **${messages.size}** messages were deleted from ${channel.mention}.`);
interaction.reply({embeds: [Response]});
})
}
}
}
channel.mention
不是 discord.js 中的东西。
.setDescription(`️ **${messages.size}** messages were deleted from ${channel}.`);
或
.setDescription(`️ **${messages.size}** messages were deleted from <#${channel.id}>.`);
- 以上两种方式都行。第一种是直接提及频道,第二种是使用频道ID来提及。
我为我的 discord 机器人发出了 purge/clear 命令,但是当我执行 /purge amount: (amount) 时,它工作正常,但机器人回复 ️ (amount) messages were deleted from undefined.
,应该是 ️ (amount) messages were deleted from #moderator-only.
。这是因为我没有正确的意图还是我做错了什么?我目前只有 SERVER MEMBERS
意图。
代码:
const { CommandInteraction, MessageEmbed } = require('discord.js');
module.exports = {
name: "purge",
description: "Deletes a specific amount of messages from a target.",
permissions: "MANAGE_MESSAGES",
options: [
{
name: "amount",
description: "Select the amount of messages to remove from the target.",
type: "NUMBER",
required: true
},
{
name: "target",
description: "Select the target to remove messages from.",
type: "USER",
required: false
}
],
/**
* @param {CommandInteraction} interaction
*/
async execute(interaction) {
const { channel, options } = interaction;
const Amount = options.getNumber("amount");
const Target = options.getMember("target");
const Messages = await channel.messages.fetch();
const Response = new MessageEmbed()
.setColor('#171717');
if(Target) {
let i = 0;
const filtered = [];
(await Messages).filter((m) => {
if(m.author.id === Target.id && Amount > i) {
filtered.push(m);
i++;
}
})
await channel.bulkDelete(filtered, true).then(messages => {
Response.setDescription(`️ **${messages.size}** messages were deleted from ${Target}.`);
interaction.reply({embeds: [Response]});
})
} else {
await channel.bulkDelete(Amount, true).then(messages =>{
Response.setDescription(`️ **${messages.size}** messages were deleted from ${channel.mention}.`);
interaction.reply({embeds: [Response]});
})
}
}
}
channel.mention
不是 discord.js 中的东西。
.setDescription(`️ **${messages.size}** messages were deleted from ${channel}.`);
或
.setDescription(`️ **${messages.size}** messages were deleted from <#${channel.id}>.`);
- 以上两种方式都行。第一种是直接提及频道,第二种是使用频道ID来提及。