试图从旧的过时指南重写Discord.py GIF Bot

试图从旧的过时指南重写Discord.py GIF Bot,discord.py,discord.py-rewrite,Discord.py,Discord.py Rewrite,好的,我正在尝试在Discord.py中重建一个GIF机器人 它基于一个网站上的一些代码,该网站提供了制作discord.pygif机器人的指南 问题是,这段代码很旧,而且严重过时,本身就有37个错误 我如何将其转换为discord.py rewrite,并基本上使其成为一个gif搜索机器人,可以通过标签从GIPHY获取随机gif 以下是我目前拥有的代码: import discord.utils import os import giphy_client from giphy_client.r

好的,我正在尝试在Discord.py中重建一个GIF机器人

它基于一个网站上的一些代码,该网站提供了制作
discord.py
gif机器人的指南

问题是,这段代码很旧,而且严重过时,本身就有37个错误

我如何将其转换为
discord.py rewrite
,并基本上使其成为一个gif搜索机器人,可以通过标签从GIPHY获取随机gif

以下是我目前拥有的代码:

import discord.utils
import os
import giphy_client
from giphy_client.rest import ApiException
from pprint import pprint
from discord.ext import commands
import random
from dotenv import load_dotenv
load_dotenv()

API_KEY = os.getenv("GIPHY_API_KEY")
API_TOKEN = os.getenv("GIPHY_API_TOKEN")

api_instance = giphy_client.DefaultApi()
config = {
    'api_key': API_KEY,
    'token': API_TOKEN,
    'limit': 1,
    'rating': 'g'
}

try:
    api_response = api_instance.gifs_trending_get(
        config['token'], limit=config['limit'], rating=config['rating'])
    pprint(api_response)

except ApiException as e:
    print("Exception when calling DefaultApi->gifs_trending_get: %s\n" % e)

Client = commands.Bot(command_prefix=os.getenv("CLIENT_PREFIX"))


class DiscordClient(discord.Client):


    @Client.event
    async def on_ready(self):
        print("Connected to Discord Client as")
        print(f'{self.user.name}#{self.user.discriminator}')
        print("-------")

    @Client.command(name="gif")
    async def search_gifs(query):
        try:
            giphy_token = API_TOKEN
            response = api_instance.gifs_search_get(giphy_token, query, limit=3, rating='g')
            lst = list(response.data)
            gif = random.choices(lst)

            return gif[0].url

        except ApiException as e:
            return "Exception when calling DefaultApi->gifs_search_get: %s\n" % e

    async def on_ready(self):
        print("Connected to Discord Client as")
        print(Client.user.name)
        print("-------")

    @Client.command(name='gif')
    async def search_gifs(query):
        try:
            response = api_instance.gifs_search_get(
                API_TOKEN, query, limit=3, rating='g')
            lst = list(response.data)
            gif = random.choices(lst)
            return gif[0].url
            except ApiException as e:\
                return "Exception when calling DefaultApi->gifs_search_get: %s\n" % e\


    @Client.command(name='8ball')
    async def magic_eight_ball(ctx):
        response = [
            'Without a doubt.',
            'Outlook good.',
            'Better not tell you now.',
            'Cannot predict now.',
            'My reply is no.',
            'Outlook not so good.',
        ]
        gif = await search_gifs('cheese')
        await ctx.send(random.choice(response))
        await ctx.send('Gif URL : ' + gif)


Client.run(os.getenv("CLIENT_TOKEN"))
这是我从以下网站获得的代码:

以下是我目前拥有的
requirements.txt
文件:

discord.py
giphy_client
python-dotenv
任何帮助都将不胜感激

我通过Heroku托管,因为我的VPS被转储,所以我在那里有
os.getenv(“…”)


我已经得到了大约7个错误,8个警告和8个弱警告。但这是我能做到的最远的地方。

伙计,请检查一下,太长了,没有人会回答这种问题。重新格式化了问题。你遇到了什么样的错误?基本上,它甚至没有运行,PyCharm发现至少还有7个错误,8个警告和8个弱警告。我希望至少能让它基本上起作用。