Discord.py |我正在尝试使用会员名称和会员 ID 使我的机器人解除禁令
Discord.py | I'm trying to make my bot unban with both Member Name and Member ID
我的代码(在 Cog 内):
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):
但仍然没有任何效果...
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,因此 discord 可以在他们的数据库中找到用户。
我的代码(在 Cog 内):
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):
但仍然没有任何效果...
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,因此 discord 可以在他们的数据库中找到用户。