【发布时间】:2021-02-25 09:22:50
【问题描述】:
事先:我已经尝试了很多可能的堆栈溢出修复。遗憾的是,它们都没有奏效。
代码如下:
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')
【问题讨论】:
-
您正在使用装饰器
@bot.command()但您正在定义client = discord.Client您可能希望将其更改为bot = commands.Bot(command_prefix='your prefix', intents=intents) -
噢,是的。实际上我已经有了它: bot = commands.Bot(command_prefix='!', case_insensitive=True) 我只是在上面的代码中错过了它 - 抱歉!
-
但是你在里面添加了意图吗?
-
guild_subscriptions是否启用? -
伙计们!谢谢你们两个 - 它奏效了! :)))) 我将更改上面的代码!
标签: python python-3.x discord bots discord.py