我正在尝试在服务器中获得一个bot,当它被dm'ed时,它会给用户一个特定的角色。现在我只在服务器中使用命令时才让它工作。有没有办法让它进入dm频道
@client.command(brief="Sets favorite programming language", description="Set a role as either Python, C++, C#, or Java",
aliases=["lang"])
async def language(ctx, lang=""):
if isinstance(ctx.channel, discord.DMChannel):
if lang.lower() not in ["python", 'c++', 'java', 'c#']:
await ctx.send("The available languages are Python, C++, C#, and Java.")
else:
await ctx.send("Your role is now " + lang.lower().capitalize() + ".")
await ctx.message.add_reaction("👌")
role = get(client.get_guild(guild_id).roles, name=lang.lower().capitalize())
print(ctx.message.author.guild(guild_id).roles)
roles = [role for role in ctx.message.author.roles if role.name in ['C++', "Java", 'Python', 'C#']]
await ctx.message.author.remove_roles(*roles)
await ctx.message.author.add_roles(role)
您需要找到要将规则授予该公会中的用户的公会
如果您的bot是一台服务器的私有bot,您可以获取服务器id并使用
client.get_guild(id)
并将公会用作参考,或者如果您的bot是一个公共bot,将在多台服务器中使用,您应该添加另一个参数作为公会id,由用户提供如果您要制作一个私人机器人,那么以下是您编辑的代码:
如果你是一个公共机器人
相关问题 更多 >
编程相关推荐