Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python discord.py on_member_join()是';行不通_Python_Python 3.x_Discord_Bots_Discord.py - Fatal编程技术网

Python discord.py on_member_join()是';行不通

Python discord.py on_member_join()是';行不通,python,python-3.x,discord,bots,discord.py,Python,Python 3.x,Discord,Bots,Discord.py,事先:我已经尝试了很多潜在的修复方法,它们可以用于堆栈溢出。可悲的是,他们都没有工作 代码如下: import discord import asyncio import datetime from discord.ext import commands bot = commands.Bot(command_prefix='!', case_insensitive=True) @bot.event async def on_ready(): print('bot is online'

事先:我已经尝试了很多潜在的修复方法,它们可以用于堆栈溢出。可悲的是,他们都没有工作

代码如下:

import discord
import asyncio
import datetime
from discord.ext import commands

bot = commands.Bot(command_prefix='!', case_insensitive=True)

@bot.event
async def on_ready():
    print('bot is online')
    return await bot.change_presence(activity=discord.Activity(type=2, name='bla'))

@bot.event
async def on_member_join(member):
    embed = discord.Embed(colour=0x95efcc, description=f"Welcome! You are the {len(list(member.guild.members))} Member!"),

    embed.set_thumbnail(url=f"{member.avatar_url}")

    embed.set_author(name=f"{member.name}", url=f"{member.avatar_url}", icon_url=f"{member.avatar_url}")

    embed.set_footer(text=f"{member.guild}", icon_url=f"{member.guild.icon_url}")

    embed.timestemp = datetime.datetime.utcnow()

    channel = bot.get_channel(id=012391238123)

    await channel.send(embed=embed)

bot.run('Token')
bot已登录,但不会在成员加入时执行。有人知道可能出了什么问题吗?on_消息工作正常

intents = discord.Intents.all()
client = discord.Client(intents=intents)
没有帮助,在discord developer中也检查了它(服务器成员意图)。 bot还具有管理员权限

爱德华德,你好


简言之,解决方案:

imports
intents = discord.Intents(messages=True, guilds=True, members=True)
bot = commands.Bot(command_prefix='!', intents=intents, case_insensitive=True)

@bot.event
async def on_member_join(member):
    embed = discord.Embed(colour=0x95efcc, description=f"Welcome to my discord server! You are the {len(list(member.guild.members))} member!")
channel = bot.get_channel(id=12931203123)

await channel.send(embed=embed)

bot.run('token')
啊,就是这样。 由于您使用的是
commands.Bot
Bot.get\u频道
不再是一个函数(因为它不再是
discord.Client
)。尝试使用
member.guild.get\u频道


您正在使用装饰器
@bot.command()
但您正在定义
client=discord.client
您可能希望将其更改为
bot=commands.bot(command\u prefix='your prefix',intents=intents)
是的。实际上我已经有了这样的代码:bot=commands.bot(command_prefix='!',不区分大小写=True),我只是在上面的代码中错过了它-对不起!但是你在那里添加了意图吗?
guild\u订阅
启用了吗?伙计们!谢谢你们两个——成功了!:)我将更改上面的代码!