#๐Ÿ”’ Discord bot only works in dms

25 messages ยท Page 1 of 1 (latest)

blissful tapir
#

Hey, i was trying to make a discord bot in python (i have no idea how to use python or discord bots) and got it working, but only in dms, it will not respond to server messages. i ran it by a friend and he said "you aren't even using slash commands" please help

left yewBOT
#

@blissful tapir

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

blissful tapir
#

import os
import random
import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = 'token'

intents = discord.Intents.default()
intents.messages = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
print(f'{client.user.name} has connected to Discord!')

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('/d4'):
    roll = random.randint(1, 4)
    await message.channel.send(f'You rolled a d4 and got: {roll}')
elif message.content.startswith('/d6'):
    roll = random.randint(1, 6)
    await message.channel.send(f'You rolled a d6 and got: {roll}')
elif message.content.startswith('/d8'):
    roll = random.randint(1, 8)
    await message.channel.send(f'You rolled a d8 and got: {roll}')
elif message.content.startswith('/d10'):
    roll = random.randint(1, 10)
    await message.channel.send(f'You rolled a d10 and got: {roll}')
elif message.content.startswith('/d12'):
    roll = random.randint(1, 12)
    await message.channel.send(f'You rolled a d12 and got: {roll}')
elif message.content.startswith('/d20'):
    roll = random.randint(1, 20)
    await message.channel.send(f'You rolled a d20 and got: {roll}')

client.run(TOKEN)

blazing dagger
steel stone
#

This ^

blissful tapir
#

nvm i cant get it in

#

its over 2000 words

supple river
#

!paste

left yewBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

blissful tapir
#

ok

twilit cove
#

You're using a very outdated tutorial/guide, or doing things very wrong from how they're done now. We don't listen to on_message to invoke commands

blissful tapir
#

oh, the tutorial im using is like 2 years old

#

thats probably it

twilit cove
#

You should be using the Discord.py library, I don't know what you're using

blissful tapir
#

alr

twilit cove
#

There was a time when DPY stopped development and a few other "alternatives" sprouted up, but DPY is the standard for python-discord bots

#

oops

#

there's a discord.py discord server that has more updated info than anywhere else on the net

blissful tapir
#

could you send the link for that server?

twilit cove
#

I tried and it was auto-deleted, I can dm you though

blissful tapir
#

no idea if my dms are open but you can try

left yewBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.