【发布时间】:2020-11-18 02:21:52
【问题描述】:
我正在尝试在服务器中安装一个机器人,当它被 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)
【问题讨论】:
标签: python discord.py discord.py-rewrite