如何在 Cogs 中正确定义全局消息?

时间:2021-04-30 15:36:52

标签: python discord discord.py

import discord
import asyncio
import random
import json
from discord.ext import commands
from discord.ext.commands.cooldowns import BucketType
from pretty_help import DefaultMenu, PrettyHelp
import os, sys

class fun(commands.Cog):
  def __init__(self, bot):
    self.bot = bot
    self._last_member = None

  global bef 
  bef = {}
  @commands.Cog.listener()
  async def on_message_edit(self, message_before, message_after):
          auuthor = message_before.author
          guild = message_before.guild.name
          chaannel = message_before.channel
          aft= message_after.content
          bef = message_before.content
          global bef
          print(f"{bef}/{aft}")

  @commands.command()
  async def editsnipe(self, ctx):
      global bef
      embed = discord.Embed(description=bef , color=discord.Color.dark_purple() )
      embed.set_author(name=f"Sniped {author.name}#{author.discriminator}", icon_url=author.avatar_url)
      embed.set_footer(text=f"edited in : #{channel_name}")
      await ctx.channel.send(embed=embed)

def setup(bot):
  bot.add_cog(fun(bot))

我每次使用该命令时都会回复 {}。如果我删除 bef = {},它会给出未定义 bef 的错误。 我怎样才能使 bef 不为空?

0 个答案:

没有答案