首页 > 解决方案 > heroku 上的 Discord.py | 命令不起作用

问题描述

我正在为我的服务器编写一个不和谐的机器人,但我想将它托管在heroku上,机器人运行它变成了在线但我的命令不起作用。我试图在 virtualenv 上运行它,但它也没有在那里工作我没有得到这个错误。

魔法rx.py

import discord
from discord.ext import commands, tasks
from itertools import cycle
from datetime import datetime


client = commands.Bot(command_prefix="rx!")
status = cycle(["rx! | reisgoldmanX", "313"])
client.run("HIDDEN_TOKEN")


now = datetime.now()
t_string = now.strftime("%d/%m/%Y")
s_string = now.strftime("%H:%M:%S")


@client.event
async def on_ready():
    change_status.start()
    print("Bot is ready.[magic /w rx]")


@client.command()
async def ping(ctx):
    await ctx.send(f"Pong! {round(client.latency * 1000)}ms latency.")


@client.command()
@commands.has_role(' | Yönetici')
async def clear(ctx, amaount=5):
    await ctx.channel.purge(limit=amaount)

@client.command()
@commands.has_role(' | Yönetici')
async def unban(ctx, *, member):
    banned_users = await ctx.guild.bans()
    member_name, member_discriminator = member.split("#")
    for ban_entry in banned_users:
        user = ban_entry.user
        if (user.name, user.discriminator) == (member_name, member_discriminator):
            await ctx.guild.unban(user)


@client.command()
@commands.has_role(' | Yönetici')
async def kick(ctx, member : discord.Member, *, reason=None):
    await member.kick(reason=reason)


@client.command()
@commands.has_role(' | Yönetici')
async def ban(ctx, member: discord.Member, *, reason=None):
    await member.ban(reason=reason)


@client.command()
async def mat(ctx, sayi1, işlem, sayi2):
    if işlem == "+":
        await ctx.send(int(sayi1) + int(sayi2))
    if işlem == "-":
        await ctx.send(int(sayi1) - int(sayi2))
    if işlem == "*":
        await ctx.send(int(sayi1) * int(sayi2))
    if işlem == "/":
        await ctx.send(int(sayi1) / int(sayi2))


@client.command(pass_context=True)
async def mathelp(ctx):
    embed = discord.Embed(
        colour=discord.Colour.dark_blue()
    )
    embed.set_author(name="Usta büyücü matematiği")
    embed.add_field(name="İşlem tablosu", value="(+)  Toplama işlemi için kullanılır.\n(-) Çıkarma işlemi için kullanılır.\n(*)  Çarpma işlemi için kullanılır.\n(/)  Bölme  işlemi için kullanılır.\n", inline=False)
    embed.add_field(name="Kullanım", value="Örnek: rx!mat **sayı1** **işlem** **sayı2**", inline=False)

    await ctx.send(embed=embed)


@client.command()
async def ts(ctx):
    embed = discord.Embed(
        colour=discord.Colour.blurple()
    )
    embed.add_field(name="Tarih ve Saat", value=f"Bugünün tarihi {t_string}\nTürkiyede saat şu an {s_string}", inline=True)
    await ctx.send(embed=embed)


@client.command(pass_context=True)
async def yardım(ctx):
    embed = discord.Embed(colour = discord.Colour.dark_orange())
    embed.set_author(name="Usta büyücü yardım tablosu")
    embed.add_field(name="Prefix", value="Her komutun başına ' **rx!** ' getirilmelidir.", inline=False)
    embed.add_field(name="ping", value="Bot ile aranızdaki gecikme süresini hesaplar ve milisaniye olarak gösterir.", inline=False)
    embed.add_field(name="ts", value="Miladi takvime göre günün tarihini ve Türkiyeye göre anlık saati gösterir.", inline=False)
    embed.add_field(name="mat", value="4 işlem uygulanabilen tam sayılar ile çalışan iki girişli bir hesap makinesi görevi görür. Ayrıntılı bilgi için ' **rx!mathelp** ' .", inline=False)

    await ctx.send(embed=embed)


@tasks.loop(seconds=30)
async def change_status():
    await client.change_presence(activity=discord.Game(next(status)))

档案

worker: python3 magic_rx.py

要求.txt

git+https://github.com/Rapptz/discord.py
aiohttp<3.7.0,>=3.6.0
discord
dnspython==1.16.0
discord.py
websockets
cffi==1.14.4
pycparser==2.20
PyNaCl==1.4.0
six==1.15.0

当我运行命令时登录 Heroku

2020-12-14T07:11:52.000000+00:00 app[api]: Build started by user hidden@gmail.com
2020-12-14T07:12:17.599569+00:00 app[api]: Deploy adaaac0d by user hidden@gmail.com
2020-12-14T07:12:17.599569+00:00 app[api]: Release v25 created by user hidden@gmail.com
2020-12-14T07:12:26.000000+00:00 app[api]: Build succeeded
2020-12-14T07:12:41.329569+00:00 app[api]: Scaled to worker@1:Free by user hidden@gmail.com
2020-12-14T07:12:45.812582+00:00 heroku[worker.1]: Starting process with command `python3 magic_rx.py`
2020-12-14T07:12:46.530685+00:00 heroku[worker.1]: State changed from starting to up
2020-12-14T07:12:58.055089+00:00 app[worker.1]: Ignoring exception in command None:
2020-12-14T07:12:58.055147+00:00 app[worker.1]: discord.ext.commands.errors.CommandNotFound: Command "yardım" is not found
2020-12-14T07:13:03.799382+00:00 app[worker.1]: Ignoring exception in command None:
2020-12-14T07:13:03.799424+00:00 app[worker.1]: discord.ext.commands.errors.CommandNotFound: Command "mathelp" is not found
2020-12-14T07:13:14.951794+00:00 app[worker.1]: Ignoring exception in command None:
2020-12-14T07:13:14.951860+00:00 app[worker.1]: discord.ext.commands.errors.CommandNotFound: Command "clear" is not found

我认为我对 requirements.txt 或 magic_rx.py 有疑问。请帮忙。

标签: python-3.xherokudiscorddiscord.py

解决方案


当然它不会工作,你在添加命令之前运行机器人

# imports
import discord

# defining the bot
client = commands.Bot(...)

# adding the commands & events
@client.event
async def on_ready():
    print('Bot is ready')

@client.command()
async def foo(ctx):
    pass

# running the bot
client.run('token')

也不要将模块discord放在需求文件中,它是discord.py. 该discord库是它的克隆。


推荐阅读