首页 > 解决方案 > 试图创建一个欢迎用户的 discord.py 机器人,但似乎不起作用

问题描述

我才开始环顾四周并弄清楚 discord.py bot 是如何工作的。尝试制作一个在某个频道中欢迎人们的机器人。但无论我做什么,它似乎都不起作用。代码执行并且 on_ready 触发。但它并没有像它应该的那样欢迎用户。有人可以帮忙吗?


    import discord
    from discord.ext import commands
    from discord.ext.commands import Bot 
    from discord import Color
    import asyncio  
    import datetime
    
    intents = discord.Intents.default()
    intents.members = True
    client = discord.Client(intents=intents)
    
    client=commands.Bot(command_prefix="-")
    client.remove_command("help")
    
    @client.event 
    async def on_ready():
        print("Created by Goodboi")
        print(client.user.name)
        print("-----")
    
    @client.event
    async def on_member_join(member):
        embed = discord.Embed(colour=0xe8744f,
        description=f"Welcome to the discord server",)
        embed.set_author(name=f"{member.mention}",icon_url=f"{member.avatar_url}")
        embed.set_footer(text=f"{member.guild}",icon_url=f"{member.guild.icon_url}")
        embed.timestamp = datetime.datetime.utcnow
    
        channel = client.get_channel(id=) #usedid
        await channel.send(embed=embed)
        
    client.run('token') #usedtoken

标签: pythondiscord.py

解决方案


嗨,你必须得到这样的频道

    @client.event
    async def on_member_join(member):

        embed = discord.Embed(colour=0xe8744f,
        description=f"Welcome to the discord server",)
        embed.set_author(name=f"{member.mention}",icon_url=f"{member.avatar_url}")
        embed.set_footer(text=f"{member.guild}",icon_url=f"{member.guild.icon_url}")
        embed.timestamp = datetime.datetime.utcnow()

        channel = member.guild.get_channel(channel_id) #usedid
        await channel.send(embed=embed)

推荐阅读