#๐ Discord bot only works in dms
25 messages ยท Page 1 of 1 (latest)
@blissful tapir
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.
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)
If you have no idea how to use python or discord bots.... Discord bots are not a beginner friendly project
This ^
ik, but oh well. im getting an error about some discord slash thing in the library, heres the updated code
nvm i cant get it in
its over 2000 words
!paste
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.
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
You should be using the Discord.py library, I don't know what you're using
alr
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
could you send the link for that server?
I tried and it was auto-deleted, I can dm you though
no idea if my dms are open but you can try
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.