【问题标题】:Auto role in discord.pydiscord.py 中的自动角色
【发布时间】:2022-01-06 16:00:19
【问题描述】:

我检查了我能找到的所有代码,但它们不适用于我的机器人。我做错了什么? 它们并没有太大的不同,它们都可以工作,但在我的代码中却没有。 cmd中没有错误。 我的朋友也做不到。 Bot 具有管理员权限(我检查过) 角色 = “新闻”

@bot.event
async def on_member_join(member): 
    rank = discord.utils.get(member.guild.roles, name=role) 
    await member.add_roles(rank)
    print(f"{member} was given the {rank} role.")

第二

@bot.event
async def on_member_join( member ):
    role = discord.utils.get( member.guild.roles, id = 889869064997068810)
    await member.add_roles( role )

第三

@bot.event
async def on_member_join(member):
    role = discord.utils.get(member.guild.roles, name='Unverified')
    await member.add_roles(role)

所有没有这个自动角色的代码

import random
import json
import discord
import datetime
from lol import an
from zdar import answer_hello
from zdar import hello_words
from zdar import maternie
from zdar import answer_maternie
from discord.ext import commands
from config0 import settings 


bot = commands.Bot(command_prefix= settings['prefix'])
bot.remove_command('help')


@bot.command()
async def clear(ctx, amount = 100):
    await ctx.channel.purge( limit = amount )
@bot.command() 
async def hello(ctx):
    await ctx.send(f',{ctx.message.author.mention}!')


@bot.command()
async def cat(ctx):
    await ctx.send(random.choice(an))

@bot.command()
async def time (ctx):
    emb = discord.Embed(title = 'Титульник', colour = discord.Color.green(), url = 'https://www.timeserver.ru/cities/by/minsk')
    emb.set_author(name = bot.user.name, icon_url = bot.user.avatar_url)
    emb.set_footer ( text = ctx.author.name, icon_url= ctx.author.avatar_url)
    emb.set_image( url= 'https://i.pinimg.com/originals/3f/82/40/3f8240fa1d16d0de6d4e7510b43b37ba.gif')
    emb.set_thumbnail( url= 'https://static.wikia.nocookie.net/anime-characters-fight/images/9/90/Eugo_La_Raviaz_mg_main.png/revision/latest/scale-to-width-down/700?cb=20201114130423&path-prefix=ru')
    now_date = datetime.datetime.now()
    emb.add_field( name = 'Time', value='Time:{}'.format( now_date))

    await ctx.send(embed = emb)

bot.run(settings['token'])

【问题讨论】:

  • 您是否尝试过设置前缀而不是从settings 检索它?
  • 我试过了,但我会仔细检查。
  • 它不起作用@Dominik
  • 这只是关于事件还是命令?您需要在 Developer Portal 中启用 Intents 并添加一些代码。从文档中查看以下内容:discordpy.readthedocs.io/en/stable/intents.html(您需要 members Intent)
  • @Dominik 机器人拥有管理员权限。

标签: python discord discord.py


【解决方案1】:

您必须指定member intent 才能接收on_member_join 事件。您可以在创建机器人对象时通过添加意图选项来执行此操作:

intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(command_prefix=settings['prefix'], intents=intents)

注意

如果您的机器人经过验证,您需要SERVER MEMBERS INTENT,您可以在应用程序的机器人页面上请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2021-02-07
    • 2020-08-03
    • 2018-04-15
    • 2021-04-15
    • 1970-01-01
    相关资源
    最近更新 更多