我正在尝试执行!ban命令,该命令在实现时会要求我确认是否要以特定表情符号作为响应来禁止或不禁止。如果我对竖起大拇指的表情符号有反应,它将发送一条消息“您可以禁止”(暂时),以及另一条消息,让您对竖起大拇指的表情符号做出反应。另外,我希望机器人仅接受发起命令!ban的人员的反应。
问题是:当我运行代码并单击任一表情符号时,什么都没有发生。我认为这主要是由于机器人无法获取创建!ban命令的人然后做出反应的原因?我真的不知道该如何获取。
请帮助我!这是我的代码:
import os
import discord
from discord import guild, message
from discord.ext import commands
from dotenv import *
import logging
import random
logging.basicConfig(level=logging.INFO)
bot = commands.Bot(command_prefix="!")
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('GUILD_ID')
@bot.command(name="ban", help="Bans someone from the server")
@commands.has_permissions(ban_members=True)
async def ban(ctx, user: int, reason: str):
author = ctx.message.author
guild = discord.utils.get(bot.guilds, id=GUILD)
mem = bot.get_user(user)
name = mem.display_name
discrim = mem.discriminator
time = ctx.message.created_at
embed = discord.Embed(title="Banning User", description=f"Do you want to ban {name}{discrim} ({user})"
f" from the server for {reason}?")
embed.set_footer(text=time)
msg = await ctx.send(embed=embed)
await msg.add_reaction(emoji="\U0001F44E")
await msg.add_reaction(emoji="\U0001F44D")
@bot.event
async def on_reaction_add(reaction, user):
if reaction.message.author == bot:
if user == ban.author:
if reaction.emoji == "\U0001F44E":
mesg = "You can ban!"
else:
mesg = "You cannot ban!"
await reaction.message.channel.send(mesg)
bot.run(TOKEN)