【发布时间】:2021-05-31 04:40:49
【问题描述】:
autoroles = {}
@client.event
async def on_ready():
global autoroles
with open("autorole.json", "r") as f:
autoroles = json.load(f)
@client.event
async def on_member_join(member):
#my welcome command is also here
await member.add_roles(autoroles[member.guild])
@client.command()
@commands.has_permissions(administrator=True)
async def autorole(ctx, *, role : discord.Role=None):
embed=discord.Embed(color=0x7289da, description=f"**Set autorole to** {role.mention}**?**")
embed.set_footer(text="React with the wave reaction to confirm it!")
msg = await ctx.send(embed=embed)
def checkifnotbot(reaction, user):
return user != client.user
await msg.add_reaction('????')
reaction, user = await client.wait_for("reaction_add", timeout=60.0, check=checkifnotbot)
if str(reaction.emoji) == "????":
embedw=discord.Embed(description=f"????**Autorole set!**\n> Everytime someone joins the server they get the {role.mention} role!", color=0x7289da)
await msg.edit(embed=embedw)
await msg.clear_reactions()
global autoroles
autoroles[str(ctx.guild.id)] = role.id
with open("autorole.json", "w") as f:
json.dump(autoroles, f)
我想要发生的事情:如果有人使用 autorole 命令,一旦有人加入服务器,角色就会被添加(适用于多个不和谐服务器) 问题:我没有收到任何错误,但只是没有添加角色。我认为这是因为 .add_roles 不想要一个 id 而是一个角色对象。但我不知道该怎么做 注意: 设置有效,它被添加到 json 文件 https://imgur.com/SRRsJgT 我也试过这个: https://pastebin.com/eCp4HN7F
【问题讨论】:
标签: python discord.py roles