【问题标题】:Discord.py Priveleged Intents stopping on_message and commands from workingDiscord.py 特权意图停止 on_message 和命令工作
【发布时间】: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


    【解决方案1】:

    我猜想使用intents = discord.Intents() 会将所有意图设置为False

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

    【讨论】:

    • 这是Intents.all() 而不是intents.all()。后者由于它是一个类方法,因此无法按预期工作。
    • 它工作正常,因为intents 是存储discord.Intents() 的变量。
    • 我的示例使用 python 3.8 没有按预期工作。我需要以另一种方式调用它,我注意到了这一点,因为它在源代码中被标记为 clasmethod。
    • 您是否使用Intents = discord.Intents() 而不是intents = discord.Intents()
    • No....我熟悉 Python。正如我所指出的,您的代码不正确并且无法按预期工作。它可能会运行和解释,但根据 Discord API,它不会像预期的那样使用位字段。有一天,我可能会发布一个完整的答案来证明这一点。
    猜你喜欢
    • 2018-12-16
    • 2021-02-25
    • 2021-07-09
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多