[英]discord.js v13 message is not defiened?
我正在使用 v12,现在无论如何我都必须升级 v13。 现在我正在尝试斜杠命令。 但我收到一个错误,相同的命令在我的前缀上工作正常,但在斜杠上它不起作用。
client.on('messageCreate', message => {
const guildId = "914573324485541928"
const guild = client.guilds.cache.get(guildId)
let commands
if (guild) {
commands = guild.commands
} else {
commands = client.application.commands
}
commands.create({
name: 'ping',
description: 'Replies with pong'
})
commands.create({
name: 'truth',
description: 'Replies with a random truth question'
})
commands.create({
name: 'dare',
description: 'Replies with a random dare question'
})
commands.create({
name: 'truthbangla',
description: 'Replies with a random bangla truth question'
})
commands.create({
name: 'darebangla',
description: 'Replies with a random bangla dare questions'
})
commands.create({
name: 'invite',
description: 'Get the invite link of this bot'
})
commands.create({
name: 'help',
description: 'Replies with all list of commands'
})
commands.create({
name: 'vote',
description: 'Get the vote url to vote our bot'
})
commands.create({
name: 'info',
description: 'Replies with all info of this bot'
})
});
client.on('interactionCreate', async (interaction) => {
if(!interaction.isCommand()){
return
}
const { commandName, options } = interaction
if(commandName === 'help'){
const user = interaction.options.getUser('target');
const help = new MessageEmbed()
.setColor('#111133')
.setTitle("Truth Or Dare")
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
.addFields(
{ name: 'For Help', value: '```+help```' },
{ name: 'For Your Truth', value: '```+t```', inline: true },
{ name: 'For Your Dare', value: '```+d```', inline: true},
{ name: 'For Invite this bot on your server', value: '```+invite```' },
{ name: 'For Truth Questions Bangla', value:'```+tb```', inline: true},
{ name: 'For Dare Questions Bangla', value:'```+db```', inline: true},
{ name: 'For Vote Our Bot', value:'```+vote```'},
{ name: 'Created By', value: '<@723821826291138611> [**Leader at CODE HUNTER**]' },
)
.setDescription(
`Truth Or Dare Bot Version: v${require("./package.json").version}
[Website](https://web-truthordare.web.app/) | [Support Server](https://discord.gg/djhNPX2QUp) | By [Code Hunter](https://github.com/Code-Hunter-OfficialBD/)`
)
.setTimestamp()
.setFooter(`${message.author.username} `, message.author.displayAvatarURL());
interaction.reply({
embeds: [help]
})
}
})
这就是错误
.setFooter(`${message.author.username} `, message.author.displayAvatarURL());
^
ReferenceError: message is not defined
现在我不知道怎么了,但在我的主要前缀中它完美地工作。 在斜杠命令中它很烂。 我该怎么办??
我相信您正在尝试引用message
而不是interaction
。 您正在interactionCreate
中运行该代码并将您的参数命名为interaction
。
const help = new MessageEmbed()
// ...
.setFooter(interaction.user.username, interaction.user.displayAvatarURL());
你得到的错误总结得很好。 您从未在这里声明过消息。 您应该记住,当您使用斜杠命令时; 你正在处理交互。
https://discord.js.org/#/docs/main/stable/class/Interaction
在这种情况下,您应该执行以下操作:
.setFooter(`${interaction.member.displayname} `, interaction.user.displayAvatarURL());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.