Home > Net >  Discord.py bot commands don't respond when using Heroku
Discord.py bot commands don't respond when using Heroku

Time:04-24

I have a pre made Code with Discord.py and hosted using Heroku, it is currently online except that whenever i use a command, it returns nothing, but when running it locally using Notepad the commands are working just fine.

main.py

import discord
from discord.ext import commands
token = 'OBVIOUSLY THE TOKEN IS HERE'
prefix = "?"
intents = discord.Intents.default() # or .all() if you ticked all, that is easier
intents.members = True # If you ticked the SERVER MEMBERS INTENT

bot = commands.Bot(command_prefix=prefix, intents=intents) # "Import" the intents
@bot.event
async def on_ready():
    print('Internal has connected to Discord!')
    await bot.change_presence(activity=discord.Game(name="Discord"))
    
@bot.command()
async def ping(ctx):
    await ctx.send(f'Pong! In {round(bot.latency * 1000)}ms')

@bot.command()
async def about(ctx):
    embed = discord.Embed(title='About me!', description=f'Im an Utility bot, that is coded under discord.py\n\n> Statistics\nLatency: `{round(bot.latency * 1000)}`ms', color=0xEE8700)
    await ctx.send(embed=embed)

@bot.command()
async def say(ctx, *, content:str):
    await ctx.send(content)

bot.run(token)

Versions: python= 3.8.8 discord.py= 1.7.3

CodePudding user response:

(Adding this as an answer because I assume someone else will have this problem)

In discord.py version 1.7.3, the messages intent, which is required for viewing message content, is set enabled by default. However, in 2.x you need to set it separately.

You can solve the issue by:

  1. Force discord.py version to go back to 1.7.3 in requirements.txt; or
  2. Explicitly enable the intents by doing intents.message_content = True.
  • Related