我現在使用的是 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
現在我不知道怎么回事,但在我的主要前??綴中它完美地作業。在斜線命令中它很糟糕。我該怎么辦??
uj5u.com熱心網友回復:
我相信您正在嘗試參考message而不是interaction. 您正在運行該代碼interactionCreate并將您的引數命名為interaction.
const help = new MessageEmbed()
// ...
.setFooter(interaction.user.username, interaction.user.displayAvatarURL());
uj5u.com熱心網友回復:
你得到的錯誤總結得很好。您從未在此處宣告過訊息。您應該記住,當您使用斜杠命令時;你正在處理互動。
https://discord.js.org/#/docs/main/stable/class/Interaction
在這種情況下,您應該執行以下操作:
.setFooter(`${interaction.member.displayname} `, interaction.user.displayAvatarURL());
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/369191.html
標籤:javascript 不和谐 不和谐.js
上一篇:我可以通過在Promise中拋出例外來中斷Javascript嗎?未處理的承諾拒絕警告
下一篇:如何解決JSX中的無限回圈?
