首页 > 解决方案 > Discord.py 特权意图停止 on_message 和命令工作

问题描述

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 文档中找到了这一点,并且在我的代码开头添加了意图位后,on_member_join、on_member_remove 和 on_member_update 工作,但是 on_message 事件和所有命令都不起作用(我添加了一个打印在 on_message 的开头并没有发生任何事情)。经过一些调试后,我发现阻止命令响应的代码似乎是,intents = intents) . 但是,当它被删除时,on_member_join、on_member_remove 和 on_member_update(可以理解)不会触发。

有什么建议吗?

标签: pythondiscord.pydiscord.py-rewrite

解决方案


我猜 usingintents = discord.Intents()的所有意图都设置为False.

您可以使用intents.messages = Trueintents.all()


推荐阅读