0

I have a discord.py bot that when the command is sent through DM, it works. When the command is ran through a server, nothing happens. There is no errors or tracebacks. Here is my code so far.

import discord
from discord.ext import commands

bot = discord.Bot()

TOKEN = "MyToken"

bot = commands.Bot(command_prefix="$")

@bot.command()
async def test(ctx, arg):
    await ctx.send(arg)

bot.run(TOKEN)

I don't know whats happening. I gave it the right permissions but it still wont do anything.

limegradient
  • 66
  • 10
  • 1
    Enable your [intents](https://discordpy.readthedocs.io/en/latest/api.html?highlight=client#discord.Intents) in the developer portal and configure it in your bot. – 3nws Apr 21 '22 at 19:03
  • @3nws how do I do that? – limegradient Apr 21 '22 at 19:06
  • 1
    Check [How do I get the discord.py intents to work?](https://stackoverflow.com/questions/64831017/how-do-i-get-the-discord-py-intents-to-work). – 3nws Apr 21 '22 at 19:13
  • What is your discordpy version? If there's no errors, I would assume it's not the version where you get message intents yet. You should probably upgrade to the latest version. – Eric Jin Apr 21 '22 at 20:04
  • @EricJin my version is 1.7.3, the latest version – limegradient Apr 22 '22 at 12:51
  • Why do you have `discord.Bot` and also the commands bot? I think you’re only supposed to use the commands bot. – Eric Jin Apr 22 '22 at 14:09

2 Answers2

1

So, I don't know for sure if this is the issue, but try this:

I have my bot set as:

bot = commands.Bot(command_prefix= '$', description="<desc>")

Rather than yours which is BOTH of these:

bot = discord.Bot()

&

bot = commands.Bot(command_prefix="$")

I think it's only detecting the first value you've given your bot.

clxrity
  • 378
  • 2
  • 9
0

For this, I believe you have fiddled it up by using the bot = variable twice, in two different ways. The way I would do it is as following:

First, import our libraries and define the token:

import discord
from discord.ext import commands

TOKEN = "MyToken"

Next, we need to set up the bot variable, as so:

bot = commands.Bot(command_prefix='$', intents=discord.Intents.all()) # I usually add all intents, you can use discord.Intents.default if you like.

I add intents because Discord sometimes gets angry if you do not, so I like to make it a just in case backup.

Now, we create the command:

@bot.command()
async def test(ctx, arg):
    await ctx.send(arg)

And lucky last, log into our bot:

bot.run(TOKEN)

Prior to our command, you can enter an on_ready function to verify the bot has logged in correctly:

@bot.event
async def on_ready():
    print(f"{bot.user} logged in successfully.")