簡體   English   中英

discord.py on_member_join() 不工作

[英]discord.py on_member_join() isn't working

事先:我已經嘗試了很多潛在的修復程序,這些修復程序可用於堆棧溢出。 可悲的是,他們都沒有工作。

這是代碼:

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)

沒有幫助,在 discord 開發人員中,它也被檢查(服務器成員意圖)。 該機器人還具有管理員權限

問候愛德華


解決方案簡而言之:

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_channel不再是 function (因為它不再是discord.Client )。 嘗試改用member.guild.get_channel

文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM