0

I've programmed several Discord bots and am back after a long break. I am currently struggling with stuff that I used to be able to accomplish in no time. I set up my bot and added a single cog, a single test command, and a listener to feel if there is anything new but now I can't get anything to work properly. My prefix commands aren't working, messages don't seem to carry .content anymore and I can't trigger functions in my cogs.

Main file:

import nextcord as discord
from nextcord.ext import commands

intents = discord.Intents.default()
intents.message_content = True
intents.members = True

bot = commands.Bot(command_prefix = "!", intents = intents)

@bot.event
async def on_ready():
    bot.load_extension("Button Roles")
    print("Ready")

@bot.event
async def on_message(message):
    if message.author.bot == False:
        #await message.channel.send(message.content)
        print(message)
        
@bot.command()
async def ping2(ctx):
    print("Pong2!")
    await ctx.send("Pong!")

bot.run("Token placeholder")

Cog:

import nextcord as discord
from nextcord.ext import commands
from nextcord import Interaction


class RoleButton(discord.ui.View):

    def __init__(self):
        super().__init__(timeout = None)
        self.value = None

    @discord.ui.button(label = "Role1", style = discord.ButtonStyle.green)#Green, Gray, Blurple, Danger
    async def Role1(self, button: discord.ui.Button, i: Interaction):
        await i.response.send_message("Role 1", ephemeral = True)
        self.value = 1
        self.stop()

    @discord.ui.button(label = "Role2", style = discord.ButtonStyle.danger)#Green, Gray, Blurple, Danger
    async def Role2(self, button: discord.ui.Button, i: Interaction):
        await i.response.send_message("Role 2", ephemeral = True)
        self.value = 2
        self.stop()
    
class Roles(commands.Cog):

    def __init__(self, bot):
        self.bot = bot
        print("Cog ready")

    testServerId = 946874409753403422

    @commands.command()
    async def ping(self, ctx):
        await ctx.send("Pong!")
    
    @commands.command()
    async def roleMessage(self, ctx):
        view = RoleButton()
        await ctx.send("You have two options:", view = view)
        await view.wait()

        if view.i.value == None:
            return
        elif view.i.value == 1:
            print("Role 1!")
        elif view.i.value == 2:
            print("Role 2!!")
            

def setup(bot):
    bot.add_cog(Roles(bot))

Outputs:

Cog ready
Ready
<Message id=993515538649202748 channel=<TextChannel id=946874410286084129 name='general' position=1 nsfw=False news=False category_id=946874410286084127> type=<MessageType.default: 0> author=<Member id=355727891180290070 name='ℭruenie' discriminator='8426' bot=False nick=None guild=<Guild id=946874409753403422 name="Project" shard_id=0 chunked=True member_count=4>> flags=<MessageFlags value=0>>

Expected Output (Using message.content instead of message):

Cog ready
Ready
'Hi'

#When I use !ping or !ping2 I don't get any outputs/messages

I have enabled the Intents from the Developer Portal.

Cruenie
  • 5
  • 3
  • Does this answer your question? [Why does on\_message stop commands from working?](https://stackoverflow.com/questions/49331096/why-does-on-message-stop-commands-from-working) – TheFungusAmongUs Jul 04 '22 at 17:35
  • I kept fixing stuff and adding others at the same time so I guess right when I fixed it, I overrode the on_message function. Idk how I missed that out, thank you for pointing such a tiny thing out. It fixed the problem for me. If you submit an answer, I can mark it as the solution. @TheFungusAmongUs – Cruenie Jul 04 '22 at 22:33
  • Actually, I flagged this question as a duplicate. It's better not to answer duplicate questions as this can "clog" up the site with multiple similar questions. Instead, there should be some question at the top of your screen that asks you whether this post answers your question. If you click "yes" all will be good and this question will be marked as a duplicate. Let me know if that works :) – TheFungusAmongUs Jul 11 '22 at 02:40

0 Answers0