I'm trying to send a DM from our Discord bot to the user when they use one of the new Discord slash commands.
The code is below. The Discord docs say that `interaction.member should be a Discord GuildMember, however, the code below gives me the following error:
TypeError: interaction.member.send is not a function
I can call other local functions from the data field but have been unable to figure out how to DM the user back. I assume I'm doing something wrong (per the error), but I can't figure out the cookbook to DM the user from the slash command callback.
client.ws.on("INTERACTION_CREATE", async (interaction) => {
const command = interaction.data.name.toLowerCase();
const args = interaction.data.options;
if (command == "testing") {
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 2,
data: interaction.member.send("hello").catch(console.error),
},
});
}
});
EDIT: Final solution with help from Jakye. Note, I had to use "fetch" instead of "get", because get kept returning an undefined user.
if (command == 'testing') {
client.users.fetch(interaction.member.user.id)
.then(user => user.send("hello").catch(console.error))
.catch(console.error);
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 2,
}
});
}