消息没有定义



我得到一个错误,说我没有定义message

content: `🏓Latency is ${Date.now() - message.createdTimestamp}ms.`,
^
ReferenceError: message is not defined
const Discord  = require('discord.js');
const client = new Discord.Client();
const prefix = '.';
const fs = require('fs');
const guildId = ''
const getApp = (guildId) => {
const app = client.api.applications(client.user.id)
if (guildId) {
app.guilds(guildId)
}
return app
}
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', async () => {
console.log('HenBot Is Online!');
const commands = await getApp(guildId).commands.get()
console.log(commands)
await getApp(guildId).commands.post({
data: {
name: 'ping',
description: 'Bots Latency',
},
})
client.ws.on('INTERACTION_CREATE', async (interaction, message) => {
const slashCommmand = interaction.data.name.toLowerCase()
if(slashCommmand === 'ping') {
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: `🏓Latency is ${Date.now() - message.createdTimestamp}ms.`,
},
},
})
}
})
})
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping') {  
client.commands.get('ping').execute(message, args);
}
})

这是因为message不是interactionCreate的有效参数。

正如discord.js文档所暗示的那样,您只能在interactionCreate事件中传递interaction

这应该适用于你的代码:

content: `🏓Latency is ${Date.now() - interaction.createdTimestamp}ms.`,

interactionCreateevent cannot havemessageparameter…

client.on('interactionCreate', async interaction => {
// your code here
})

最新更新