【问题标题】:discord.py on_member_join event not triggeringdiscord.py on_member_join 事件未触发
【发布时间】:2021-04-05 09:49:40
【问题描述】:

我正在尝试触发 on_member_join 事件,但当有人加入时它不会触发。我也试图在加入时给某人一个角色,但我几乎知道如何做到这一点。我只是不明白为什么这个事件没有在加入时触发。它正在工作,但它停止了。

bot = commands.Bot(command_prefix="!")



player = {}

# Events

@bot.event
async def on_ready():
     print("Bloody Admin is online:")
     await bot.change_presence(status=discord.Status.online, activity=discord.Game("Prefix: !"))
     
     
@bot.event
async def on_member_join(member):
     print("Joined")
    
@bot.event
async def on_member_remove(member):
     await member.create_dm()
     await member.send("I guess I watched you too hard, sorry to see you leave :(")
     

@bot.event
async def on_command_error(ctx, error):
     await ctx.send(error)

我什至尝试将其更改为客户端事件

bot = commands.Bot(command_prefix="!")

client = discord.Client()

player = {}

# Events

@bot.event
async def on_ready():
     print("Bloody Admin is online:")
     await bot.change_presence(status=discord.Status.online, activity=discord.Game("Prefix: !"))
     
     
@client.event
async def on_member_join(member):
     print("Joined")
    
@client.event
async def on_member_remove(member):
     await member.create_dm()
     await member.send("I guess I watched you too hard, sorry to see you leave :(")
     

@bot.event
async def on_command_error(ctx, error):
     await ctx.send(error)

任何帮助都会很棒。谢谢。

【问题讨论】:

  • 你有这个意图吗?

标签: python discord discord.py


【解决方案1】:

您似乎缺少 Intent。

确保为您的应用打开Discord Developer Portal 中所有必要的选项。

要将它们实现到您的代码中,您可以使用以下代码:

intents = discord.Intents.all() # Imports all the Intents
client = commands.Bot(command_prefix="YourPrefix", intents=intents)

【讨论】:

  • 我收到一条错误消息,提示 builtins.AttributeError: module 'discord' has no attribute 'Intents'。我确实导入了不和谐。
  • 我假设你有一个旧的 discord.py 版本。请至少更新到 1.5.1 或 1.6.0。实际上有一个post 解释得很好。
  • 是的,我运行的是 1.4。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-12
  • 2021-01-16
  • 1970-01-01
  • 2021-05-07
  • 2021-10-02
  • 2021-05-08
相关资源
最近更新 更多