代码之家  ›  专栏  ›  技术社区  ›  GodIsGhost

通过私人消息发送直接消息,欢迎加入服务器的新用户

  •  2
  • GodIsGhost  · 技术社区  · 7 年前

    const Discord = require('discord.js');
    const bot = new Discord.Client ();
    
    bot.on('ready', () => {
      console.log('I am ready!');
    });
    
    bot.on('guildMemberAdd', member => {
           member.guild.defaultChannel.send(`Welcome to the server, ${member}!`);
           console.log(`${member.user.username} has joined`);
    });
    
    bot.login('TOKEN_HERE');
    
    3 回复  |  直到 2 年前
        1
  •  4
  •   Wright    7 年前

    Member 对象具有与通道一样的发送方法。

    笔记

    const Discord = require('discord.js');
    const bot = new Discord.Client ();
    
    bot.on('guildMemberAdd', member => {
       member.send("Welcome to the server!");
    });
    
    bot.login('TOKEN_HERE');
    
        2
  •  0
  •   Gonçalo Peres    3 年前

    使用Python可以运行以下脚本( Source )

    # bot.py
    import os
    
    import discord
    from dotenv import load_dotenv
    
    load_dotenv()
    TOKEN = os.getenv('DISCORD_TOKEN')
    
    client = discord.Client()
    
    @client.event
    async def on_ready():
        print(f'{client.user.name} has connected to Discord!')
    
    @client.event
    async def on_member_join(member):
        await member.create_dm()
        await member.dm_channel.send(
            f'Hi {member.name}, welcome to my Discord server!'
        )
    
    client.run(TOKEN)
    

    on_member_join()

    member.create_dm() 创建直接消息通道。然后,使用该通道 .send() 给那个新成员的直接信息。

        3
  •  0
  •   Bikas Finn-Dev    2 年前
    client.on('guildMemberAdd', member => {
      member.send(`Welcome to the server, ${member}!`);
    });
    

    只需添加它,或者如果您想要更定制或使用嵌入

    client.on('guildMemberAdd', member => {
      const embed = new Discord.MessageEmbed()
        .setColor('color number')
        .setTitle('your welcome message')
        .setDescription(`yourwelcome message, ${member}!`)
        .setThumbnail(member.user.displayAvatarURL())
        .addFields(
          { name: 'User:', value: `${member.user.tag}`, inline: true },
          { name: 'ID:', value: `${member.user.id}`, inline: true },
          { name: 'Joined at:', value: `${member.joinedAt}`, inline: true },
        )   
      member.send(embed);
    })