Discord.py 特权意图停止 on_message 和命令停止工作
Discord.py Priveleged Intents stopping on_message and commands from working
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))
您好。我试图构建一个 discord Bot,除了我无法让 on_member_join & on_member_update 工作之外,我基本上是成功的(他们甚至似乎没有注册用户进入或离开服务器所以我得出结论,我缺少一些权限)。经过大量搜索后,我在 discord.py 文档中找到了 this,在我的代码开头添加了 intents 位后,on_member_join、on_member_remove 和 on_member_update有效,但 on_message 事件和所有命令均无效(我在 on_message 的开头添加了打印,但没有任何反应)。
经过一些调试,我发现停止命令响应的代码似乎是,intents = intents)
。然而,当它被删除时,on_member_join、on_member_remove 和 on_member_update(可以理解)不会触发。
有什么建议吗?
我猜测使用 intents = discord.Intents()
的所有意图都设置为 False
。
您可以使用 intents.messages = True
or intents.all()
。
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))
您好。我试图构建一个 discord Bot,除了我无法让 on_member_join & on_member_update 工作之外,我基本上是成功的(他们甚至似乎没有注册用户进入或离开服务器所以我得出结论,我缺少一些权限)。经过大量搜索后,我在 discord.py 文档中找到了 this,在我的代码开头添加了 intents 位后,on_member_join、on_member_remove 和 on_member_update有效,但 on_message 事件和所有命令均无效(我在 on_message 的开头添加了打印,但没有任何反应)。
经过一些调试,我发现停止命令响应的代码似乎是,intents = intents)
。然而,当它被删除时,on_member_join、on_member_remove 和 on_member_update(可以理解)不会触发。
有什么建议吗?
我猜测使用 intents = discord.Intents()
的所有意图都设置为 False
。
您可以使用 intents.messages = True
or intents.all()
。