python - discord.py on_member_join() 不起作用
问题描述
事先:我已经尝试了很多在堆栈溢出时可用的潜在修复。可悲的是,他们都没有工作。
这是代码:
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')
机器人登录但不会执行 on_member_join。有人知道可能出了什么问题吗?on_message 工作正常。
intents = discord.Intents.all()
client = discord.Client(intents=intents)
没有帮助,并且在不和谐的开发人员中也对其进行了检查(服务器成员意图)。该机器人还具有管理员权限
问候爱德华
简而言之,解决方案:
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
, thebot.get_channel
不再是一个函数(因为它不再是discord.Client
)。尝试member.guild.get_channel
改用。
推荐阅读
- ios - WKwebView 在 iOS 应用程序中使用 WebPageProxy 错误代码 1003 间歇性地给出错误
- python - Pandas:创建新列,根据条件从另一行中查找和选择值
- reactjs - 为什么我的 SASS 项目不考虑媒体断点?
- azure - 在 Azure 但在非 AKS Kubernetes 环境/Kubernetes Baremetal 安装中需要 Azure CNI 的问题或帮助
- javascript - React Material-UI Select未检测到滚动事件
- linux - nix::sched::clone 在 println 后导致分段错误
- heroku - 从 Freenom 添加 Heroku 自定义域
- python - 为什么我会在这个“else”语句中得到“SyntaxError: 'invalid syntax'”?
- flutter - 协助业务逻辑
- android - 如何让我的 android 模拟器正确扩展?