当前位置: 首页 > 知识库问答 >
问题:

找不到命令

阎知
2023-03-14

我有一个网络钩子齿轮为我的不和谐机器人。我想让embarss命令(在webhook cog中)触发一个webhook,创建时使用用户名和pfp,这很好。然而,我也希望这个命令能够被设置到一个特定的用户身上,这就是问题所在。当我尝试将成员参数添加到embarrass函数中时,它看起来像:async def embarrass(self、ctx、member:discord.member),但不起作用。每次执行命令之后,我都会得到一个“command embarrass not found”错误。无论我是否通过参数,也不管我是否向其中添加了member:discord.member=None以使其成为非必需的,这都是正确的;我所做的一切都不起作用。我非常感谢在这个主题上的任何帮助。

这是我的主要任务。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上运行这个。这就是为什么我导入keep_alive,我还有一个cog,我用其他命令添加了它,但这似乎也不是问题所在。我可以添加它,如果你要求的话。

谢谢你的帮助!

共有1个答案

贝杜吟
2023-03-14

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

 类似资料:
  • 问题内容: 我已经使用命令在 CentOS 5.5版 机器中安装了Java 。但是我无法使用javac编译类。 我是否需要安装其他软件包? 我试图找到可执行文件,但无法找到它。 链接如下: -> -> 我已经看到了以下输出: 问题答案: 您仅安装了Java Runtime Environment(JRE),其中不包含。为此,您必须安装OpenJDK开发环境。您可以安装或,两者都包括。 顺便说一句:

  • 问题内容: 我在修复此bash脚本中的错误时遇到问题,我真的不知道我做错了什么,感谢您的任何帮助,谢谢 问题答案: 在 之前和 之后 添加一个空格。

  • 问题内容: 尝试安装Vue,但出现错误。 一切都按照Vue的说明安装,我不确定为什么会出现此问题。 提前致谢! 问题答案: 尝试使用以下命令更新PATH变量: 更新节点/ NPM可能也有帮助。

  • 问题内容: 我正在尝试在ubuntu中运行命令 android更新项目–path。 但是我得到一个 我认为这与前几天我在这里学到的道路有关吗?我只是想知道,我需要添加什么变量(我假设是Android)以及我也需要指出什么。 问题答案: 在MacOS / Linux上,将安装SDK的路径定义为: 苹果系统 如果您安装了Android Studio,则该值必须为 的Linux 然后将路径添加到和子目录

  • 问题内容: 我在我的centOS 7服务器上安装了node.js和npm。但是我对pm2有问题。实际的问题是我没有Linux经验,也不知道如何更改路径。这是文件夹结构。 我通过输入进入文件夹,并使用安装了pm2 。 之后,我尝试通过键入server返回“找不到pm2命令” 将pm2用于我的server.js 。我可以毫无问题地使用node.js,但pm2无法正常工作。 我该如何解决? 问题答案:

  • 问题内容: 我正在尝试升级到最新版本的节点。我正在按照http://davidwalsh.name/upgrade- nodejs上 的说明进行操作 但是当我这样做时: 我得到错误: npm无需sudo即可工作。当我做: 我懂了: 运行: 显示: 但是我仍然遇到同样的错误。我还查看了/ etc / sudoers文件,相关的行是: 在我看来,这很好。如何使用sudo命令使NPM正常工作? 问题答案