简体   繁体   English

Discord.js | 如何制作在用户加入时发送用户信息的代码?

[英]Discord.js | How do I make a code that sends the users info when they join?

I am trying to make a code that sends the users avatar, username, ID, account create date, joined server date and status automatically when they join我正在尝试制作一个代码,在用户加入时自动发送用户头像、用户名、ID、帐户创建日期、加入服务器日期和状态

it looks something like this它看起来像这样

module.exports = (Discord, client, message) => {

    const ChannelID = ('731452498761613366');


    const userEmbed = new Discord.MessageEmbed()
    .setTitle(`Here is what I found about the kid`)
    .setThumbnail(displayAvatarURL())
    .addField('Username and tag:', )
    .addField('User ID:', )
    .addField('Account created:', )
    .addField('Joined the server at:', )
    .addField('User status:', )
    .setColor('5E61AB')



    guildMember.guild.channels.cache.get(ChannelID).send(userEmbed).catch(err =>  console.log(err));

}

Idk what to put at after the : but I know the .tag , .id , .createdAt .joinedAt and .presence.status . Idk 在:之后放什么,但我知道.tag.id.createdAt .joinedAt.presence.status I don't know what to put before the .不知道在前面放什么. . . I also don't use client.on because I have a specific folder called events.我也不使用client.on ,因为我有一个名为 events 的特定文件夹。 Sorry if my question is hard to understand or I'm asking a bad question or anything.抱歉,如果我的问题难以理解,或者我在问一个不好的问题或任何问题。 Does anybody know how I can make this possible?有谁知道我怎样才能做到这一点?

You should use the guildMemberAdd event for this.您应该为此使用guildMemberAdd事件。 It's pretty simple:这很简单:

First:第一的:

create a new file ( or add it to the file all your events are defined ) named guildmMemberAdd.js创建一个名为guildmMemberAdd.js的新文件(或将其添加到定义所有事件的文件中)

After that在那之后

you can define the event like this:您可以像这样定义event

Code, if you're using a command handler :代码,如果您使用的是command handler

// The order of the parameters may differ
module.exports = (Discord, member) => {
  // your code here
}

Code, if you're defining all events in your main file :代码,如果您在main file中定义所有事件:

client.on('guildMemberAdd', (member) => {
  // your code here
});

Now that you covered that, you can create your embed (this will work for both options that I showed above) :现在您已经介绍了这一点,您可以创建embed (这将适用于我上面显示的两个选项)

const newMemberEmbed = new Discord.MessageEmbed()
    .setTitle(`Here is what I found about the kid`)
    .setThumbnail(member.user.displayAvatarURL())
    .addField(`Username and tag: ${member.displayName} | ${member.user.tag}`, )
    .addField(`User ID: ${member.id}`, )
    .addField(`Account created: ${member.user.createdAt}`, )
    .addField(`Joined the server at: ${member.joinedAt}`, )
    .addField(`User status: ${member.presence.status}`, )
    .setColor('5E61AB')

If you're done with that, you're ready to send the embed :如果你完成了,你就可以send embed了:

const ChannelID = ('731452498761613366');

member.guild.channels.cache.get(ChannelID).send(newMemberEmbed).catch(err =>  console.log(err));

Hope this works:)希望这有效:)


References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 discord 机器人在 discord.js 中发送消息后有表情符号反应? - How do I make discord bot have an emoji reaction after it sends its message in discord.js? Discord.js | 我如何制作通过 id 发送到特定频道的命令 - Discord.js | How do i make a command that sends to a specific channel by id 我如何才能使它只发送消息的一部分? 不和谐.js - How do i make so it only sends a part of the message? discord.js 如果未在代码中将GuildID列入白名单,如何使Discord.js(Commando)机器人离开服务器(加入)? - How do I make my Discord.js (Commando) bot leave servers (on join) if the GuildIDs aren't whitelisted in my code? 如何制作从 discord.js 中的服务器收集用户的选择菜单 - How do I make a Selection Menu that collects users from a server in discord.js 如何获取用户活动 discord.js - How do I get the users activity discord.js 我怎样才能使这个代码循环? [discord.js] - How can I make this code loop? [discord.js] 如何在 discord.js 代码块中对 json object 值进行排序? - How do I make sort json object values in discord.js code block? 我的 discord.js 机器人发送多个 gif 而不是一个。 我该如何解决? - My discord.js bot sends multiple gifs instead of one. How do I fix this? 我如何让我的代码在删除消息之前等待(discord.js) - how do i make my code wait before deleting a message (discord.js)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM