我的代码(在一个齿轮内):
import discord
import datetime
from discord.ext import commands
class unban(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
@commands.has_permissions(ban_members = True)
async def unban(self, ctx, id: int):
user = await self.client.fetch_user(id)
await ctx.guild.unban(user)
unban= discord.Embed(title=f'A moderation action has been performed!', description='', color=0x90fd05)
#unban.add_field(name='User Affected:', value=f'`{member.name}`', inline=True)
#unban.add_field(name='User ID:', value=f'`{member.id}`', inline=True)
unban.add_field(name='Moderator Name:', value=f'`{ctx.author}`', inline=True)
unban.add_field(name='Moderator ID:', value=f'`{ctx.author.id}`', inline=True)
unban.add_field(name='Action Performed:', value='`UnBan`', inline=True)
unban.set_author(name=f'{ctx.guild}', icon_url=ctx.guild.icon_url)
#unban.set_thumbnail(url=member.avatar_url)
unban.timestamp = datetime.datetime.utcnow()
await ctx.send(embed=unban)
def setup(client):
client.add_cog(unban(client))
我已经发出命令,所以我可以解除人们的禁令。但我只能用他们的ID解禁。我也希望它以他们的名字解禁。那我该怎么做呢?
我也试过替换:
async def unban(self, ctx, id: int):
与:
async def unban(self, ctx, member : discord.Member):
但没有任何效果。我试过同时使用两者:
async def unban(self, ctx, member : discord.Member, id: int):
但仍然没有任何效果...
答案 0 :(得分:1)
async def unban(self, ctx, member : discord.Member):
它不会工作,因为被禁止的成员只能用 discord.User
或 ID 表示。
async def unban(self, ctx, user_id : int):
user = await self.client.fetch_user(user_id)
await ctx.guild.unban(user)
这仅适用于 ID,因此不和谐可以在他们的数据库中找到用户。