【发布时间】:2021-05-13 23:26:25
【问题描述】:
所以我有这个代码,我希望机器人首先将嵌入发送给要被禁止的人,然后我希望机器人禁止他/她,问题是一些用户阻止了我的机器人,因此机器人无法在 DM 中向它们发送消息,从而停止整个命令。如何使用相同的命令禁止他们?
import discord
from discord.ext import commands
class ban(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def ban(self, ctx, member : discord.Member, *, reason = None):
if (ctx.message.author.permissions_in(ctx.message.channel).ban_members):
if member.top_role >= ctx.author.top_role:
await ctx.send("You can only ban people below you")
return
if reason == None:
reason = "{}: No reason provided.".format(ctx.message.author)
embed=discord.Embed(title="You have been banned!", description="You have been banned from {} for {} by {}".format(ctx.guild, reason, ctx.author), color=0xff0000)
embed.add_field(name="In order to appeal:", value="Join the server below, then DM me saying '>apelacja'", inline=False)
embed.set_footer(text="Nims Waifu 2021")
await member.send(embed=embed)
await member.send("https://discord.gg/CxTQaYWqRK")
await member.ban(reason= "{}: {}".format(ctx.author, reason))
await ctx.send("✅ Banned {} for: {}".format(member, reason))
def setup(bot):
bot.add_cog(ban(bot))
【问题讨论】:
标签: python discord.py