const TOKEN = "mybotstoken";
const CLIENT_ID = "mybotsclientid";
const { REST, Routes } = require('discord.js');
const commands = [
{
name: 'ping',
description: 'Replies with Pong!',
},
];
const rest = new REST({ version: '10' }).setToken(TOKEN);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
const user = interaction.author;
const username = user.username;
console.log(`Got a ping execute request from: ${username}`);
await interaction.reply('Pong!');
console.log(`Execute succesful`);
}
});
client.login(TOKEN);
这个密码有什么问题吗?
我得到错误:第一个月
1条答案
按热度按时间h9vpoimq1#
因为没有
interaction.author
,你可能以为它和message.author
一样,有interaction.user
和interaction.member
,所以如果你想得到作者的用户名,可以用前者: