有没有一种简单的方法可以让我的机器人提到它要搬家的人?
Is there an easy way to make my bot mention the person its moving?
所以基本上我想让我的机器人让人们在耳聋时立即挂机。我有一个命令让它在聊天中生成消息,但问题是,我也可以@他们吗?如果是的话怎么办?
代码:
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES", "GUILD_MEMBERS", "GUILD_PRESENCES"] });
client.on("voiceStateUpdate", (oldState, newState) =>
{
if (newState.selfDeaf)
{
console.log('User has deafened');
newState.member.voice.setChannel("695840093167943751");
client.channels.cache.get("664487959940169738").send('Undeafen Bitch');
}
要在 discord 中标记用户,格式为 <@USERID> 因此如果用户的 ID 为 1,则您必须在发送的内容中包含 <@1>。
因此,在您的代码中,您必须将最后一行更改为如下内容:
client.channels.cache.get("664487959940169738").send('<@123> Undeafen Bitch');
但是我们不能对 ID 进行硬编码,因为它对于每个移动的用户都是唯一的。这应该会自动标记被移动的用户:
client.channels.cache.get("664487959940169738").send(`<@${newState.member.id}> Undeafen Bitch`);
所以基本上我想让我的机器人让人们在耳聋时立即挂机。我有一个命令让它在聊天中生成消息,但问题是,我也可以@他们吗?如果是的话怎么办?
代码:
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES", "GUILD_MEMBERS", "GUILD_PRESENCES"] });
client.on("voiceStateUpdate", (oldState, newState) =>
{
if (newState.selfDeaf)
{
console.log('User has deafened');
newState.member.voice.setChannel("695840093167943751");
client.channels.cache.get("664487959940169738").send('Undeafen Bitch');
}
要在 discord 中标记用户,格式为 <@USERID> 因此如果用户的 ID 为 1,则您必须在发送的内容中包含 <@1>。
因此,在您的代码中,您必须将最后一行更改为如下内容:
client.channels.cache.get("664487959940169738").send('<@123> Undeafen Bitch');
但是我们不能对 ID 进行硬编码,因为它对于每个移动的用户都是唯一的。这应该会自动标记被移动的用户:
client.channels.cache.get("664487959940169738").send(`<@${newState.member.id}> Undeafen Bitch`);