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订阅
启用了吗?伙计们!谢谢你们两个——成功了!:)我将更改上面的代码!