找不到相关命令

时间:2020-10-27 19:52:20

标签: discord webhooks discord.py-rewrite

我有一个用于制作不和谐机器人的webhook齿轮。我想使embarrass命令(在webhook齿轮中)触发使用用户名和pfp创建的webhook,这很好用。但是,我也希望能够将此命令设置到特定用户上,这就是问题所在。当我尝试将成员参数添加到embarrass函数中时,它看起来像:async def embarrass(s​​elf,ctx,member:discord.Member 它不起作用。每次执行命令后,都会出现“找不到命令尴尬”错误。无论我是否通过参数,以及是否添加成员,都适用:discord.Member = None,使其不需要。我没有做任何工作。非常感谢您对此主题提供任何帮助。

这是我的main.py:

import random
import asyncio
import aiohttp
import json
import keep_alive
from discord import Game
from discord.ext.commands import Bot
import datetime
import re
import time
from subprocess import call
import discord
from discord.ext import commands
from discord.utils import get
import text
import os
TOKEN = os.environ['token']
bot = commands.Bot(command_prefix=".")

startup_extensions = ["Cog.Cog_Template", "Cog.webhooks"]


@bot.event
async def on_ready():
    # On read, after startup
    print(f"Connecting...\nConnected {bot.user}\n")  # Send message on connected


if __name__ == "__main__":  # When script is loaded, this will run
    for extension in startup_extensions:
        try:
            bot.load_extension(extension)  # Loads cogs successfully
        except Exception as e:
            exc = '{}: {}'.format(type(e).__name__, e)
            print('Failed to load extension {}\n{}'.format(extension, exc))


keep_alive.keep_alive()
bot.run(TOKEN)

这是我的齿轮文件(名为webhook.py,位于一个名为齿轮的文件夹中。

from discord import Webhook, RequestsWebhookAdapter
from discord.ext import commands
import random

embarrasslist = ["I use and throughly like airpods","I respond with \"^\" to everything because I'm too dumb to have an original thought of my own","The only time I ever go outside is for school","I made a discord server where exactly 3 people joined, and they were were my alt accounts.","I get legitimately scared when I play five nights at freddy's","I play PC Games with a steam controller","I unironically use 69 in my usernames","I cried myself to sleep when I found out that my favourite chair had a dent in it","My parent's gave me a PS Move instead of a Wii for christmas","I unironically watch Ali-A","I spam .embarrass because I am very narcissistic and want to see my face on a bot", "I couldn't teach my son how to ride a bike cause I can't ride one myself","I own a sonic pillow and I kiss it every night before I go to sleep","I set my favorite 3ds game to system settings because I thought I was being clever","I set my favorite 3ds game to system settings because I can't buy any more games","Paul Blart: Maul Cop is my favorite movie","I thought shrek 3 wasn't bad","I have a gameinformer subscription","It took me a full day to beat the first level of super mario bros","My favorite emote is :joy:","I spent 2 hours learning how to make a new folder on my computer","I torrented fortnite"]
class WebHooks(commands.Cog, name="WebHooks"):
    global embarrasslist
    def __init__(self, bot):
        self.bot = bot
    @commands.command(name="embarrass")
    async def embarrass(self, ctx, member: discord.Member = None):
        """Send a message as a webhook"""
        if member != None:
          user = member
        elif member = None:
          user = ctx.message.author
        embarrassnumber = random.randint(0,21)
        embarrassment = embarrasslist[embarrassnumber]
        looking_webhooks = await ctx.channel.webhooks()
        if looking_webhooks:
            for webhook in looking_webhooks:
                if webhook.name == "NexInfinite-GitHub":
                    await send_webhook(webhook, embarrassment, ctx, user)
                    return
                else:
                    pass
        webhook = await ctx.channel.create_webhook(name="NexInfinite-GitHub")

        await send_webhook(webhook, embarrassment, ctx, user)
        return
    @commands.command(name="embaras", aliases = ["embarras","embarass"])
    async def embarras(self, ctx):
        """Send a message as a webhook"""
        cantspell = "I don't know how to spell *embarrass* properly"
        looking_webhooks = await ctx.channel.webhooks()
        if looking_webhooks:
            for webhook in looking_webhooks:
                if webhook.name == "NexInfinite-GitHub":
                    await send_webhook(webhook, cantspell, ctx)
                    return
                else:
                    pass
        webhook = await ctx.channel.create_webhook(name="NexInfinite-GitHub")
        await send_webhook(webhook, cantspell, ctx)
        return


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


async def send_webhook(webhook, message, ctx, uservar):
    webhook_id = webhook.id
    webhook_token = webhook.token
    webhook = Webhook.partial(int(webhook_id),
                              f"{webhook_token}",
                              adapter=RequestsWebhookAdapter())
    webhook.send(f'{message}', username=f"{ctx.uservar.display_name}",
                 avatar_url=ctx.uservar.avatar_url)  # Sends the message as the author

我正在repl.it上运行它,这就是为什么我导入keep_alive的原因,并且我还有其他齿轮与其他命令一起添加,但这似乎也不是问题。如果您需要,我可以添加它。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我忘记在顶部导入discord,因此无法成功使用discord.Member。导入不和谐解决了这个问题。