【发布时间】:2021-01-17 02:25:13
【问题描述】:
from discord.ext import commands
from discord.ext import tasks
import random
import typing
from discord import Status
from discord import Activity, ActivityType
from discord import Member
from discord.ext.commands import Bot
from asyncio import sleep
intents = discord.Intents()
intents.members = True
intents.presences = True
print(discord.__version__)
bot = commands.Bot(command_prefix='!', intents =intents)
...
...
@bot.event
async def on_ready():
print('hiii, We have logged in as {0.user}'.format(bot))
await bot.change_presence(activity=discord.Game(name="Exploring the archives"))
bot.loop.create_task(status())
@bot.event
async def on_message(message):
if message.author.id == BOT_ID:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello Dad!')
await bot.process_commands(message)
@bot.event
async def on_member_update(before,after):
if before.status != str(after) :
print("{}, #{} has gone {} .".format(after.name,after.id,after.status))
@bot.event
async def on_member_remove(member):
print(f'{member} has left a server.')
@bot.event
async def on_member_join(member):
print(f'{member} has joined a server.')
await member.send('Private message')
@bot.command(pass_context=True)
async def summon(ctx):
await ctx.send ("I have been summoned by the mighty {}, ".format(ctx.message.author.mention) + " bearer of {}. What is your command?".format(ctx.message.author.id))
你好。我试图建立一个不和谐的机器人,除了我无法让 on_member_join 和 on_member_update 工作(他们似乎甚至没有注册用户进入或离开服务器,所以我得出结论我缺乏一些权限)。经过大量搜索后,我在 discord.py 文档中找到了this,并在我的代码开头添加了意图位后,on_member_join、on_member_remove 和 on_member_update 有效,但 on_message 事件和所有命令都不起作用(我添加了on_message 开头的打印,没有发生任何事情)。
经过一些调试,我发现阻止命令响应的代码似乎是,intents = intents) 。但是,当它被删除时,on_member_join、on_member_remove 和 on_member_update(可以理解)不会触发。
有什么建议吗?
【问题讨论】:
标签: python discord.py discord.py-rewrite