#๐Ÿ”’ only send message in dm

9 messages ยท Page 1 of 1 (latest)

grizzled path
#

Im making a discord bot, but my bot is only responding in DM and not in my server.
this is my code, cxan someone help me to get me discord bot to respond in my server.

import discord
import os

from dotenv import load_dotenv
from discord.ext.commands import Bot
from discord.ext import commands

TOKEN='TOKEN'

load_dotenv()
TOKEN = os.getenv('TOKEN')

intents = discord.Intents.default()

client = discord.Client(intents=intents)

@client.event
async def on_ready():
print('we have logged in as {0.user}'.format(client))

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

if message.content.startswith('!hello'):
    await message.channel.send('Hello!')

client.run('TOKEN')

delicate patioBOT
#

@grizzled path

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.

half iris
#

@grizzled path did you confirm that the bot is in your server?

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

    print(message.author.name, message.content)

    if message.content.startswith('!hello'):
        await message.channel.send('Hello!')

Try adding that print statement, so that you can see if the bot sees the message.

lament crater
#

!message-content-intent

delicate patioBOT
#
Discord Message Content Intent

The Discord gateway only dispatches events you subscribe to, which you can configure by using "intents."

The message content intent is what determines if an app will receive the actual content of newly created messages. Without this intent, discord.py won't be able to detect prefix commands, so prefix commands won't respond.

Privileged intents, such as message content, have to be explicitly enabled from the Discord Developer Portal in addition to being enabled in the code:

intents = discord.Intents.default() # create a default Intents instance
intents.message_content = True # enable message content intents

bot = commands.Bot(command_prefix="!", intents=intents) # actually pass it into the constructor

For more information on intents, see /tag intents. If prefix commands are still not working, see /tag on-message-event.

delicate patioBOT
#
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.