reisgoldmanX
reisgoldmanX

Reputation: 60

Discord.py on heroku | commands doesnt work

İm writing a discord bot for my server but i wanted to host it on heroku the bot runs it becomes online but my commands doesnt work.İ tried to run it on a virtualenv and it didnt work there too i didnt get this error.

magic_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)))

Procfile

worker: python3 magic_rx.py

requirements.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

Logs on Heroku when i run a command

2020-12-14T07:11:52.000000+00:00 app[api]: Build started by user [email protected]
2020-12-14T07:12:17.599569+00:00 app[api]: Deploy adaaac0d by user [email protected]
2020-12-14T07:12:17.599569+00:00 app[api]: Release v25 created by user [email protected]
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 [email protected]
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

İ think i have a problem with requirements.txt or magic_rx.py. Please help.

Upvotes: 1

Views: 683

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15728

Of course it's not going to work, you're running the bot at the beginning before adding the commands

# 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')

Also don't put the module discord in the requirements file, it's discord.py. The discord library is a clone of it.

Upvotes: 1

Related Questions