No error but it is not running HELP Discord.py

Question:

i want to make a discord bot but i cant run it.
idk what to do
it just runs
and no log
idk REALLY what to do

import discord
from discord.ext import commands
import os
import keep_alive
client = commands.Bot(command_prefix="!")
token = os.environ.get('Token')
GUILD = os.environ.get('Guild')


async def on_ready():
    print(f'{client.user} is connected')
@client.command()
async def dm(ctx, member: discord.Member):
    await ctx.send('what do u want to say bitch!')

    def check(m):
        return m.author.id == ctx.author.id

    massage = await client.wait_for('massage', check=check)
    await ctx.send(f'send massage to {member} ')

    await member.send(f'{ctx.member.mention} has a massage for you: n {massage}')

    @client.event
    async def on_member_join(member):
            channel = discord.util.get(member.Guild, name='general')
            await channel.send(f'Hey welcome to my server {member.mention}, hope you enjoy this server!')
      


    keep_alive.keep_alive()
    client.run(token)
    client.close()

i dont know what to do anymore
I tried everything i could i ran it in pycharm
vscode
nothing works

Asked By: Mr Mortal

||

Answers:

There’s a lot of errors on your code. so I fixed it
First thing is your client events, keep_alive, client.run, also why did you put client.close()

import os, discord
import keep_alive
from discord.ext import commands

client = commands.Bot(command_prefix="!")

token = os.environ.get('Token')
GUILD = os.environ.get('Guild')


@client.event # You need this event
async def on_ready():
    print(f'{client.user} is connected')

"""
client.wait_for('massage') is invalid. Changed it into 'message'. Guess it is a typo.
You can replace this command with the new one below.
"""
@client.command()
async def dm(ctx, member: discord.Member):
    await ctx.send('what do u want to say bitch!')

    def check(m):
        return m.author.id == ctx.author.id

    massage = await client.wait_for('message', check=check)
    await ctx.send(f'send massage to {member} ')

    await member.send(f'{ctx.member.mention} has a massage for you: n {massage}')

"""
I also moved this on_member_join event outside because it blocks it.
"""
@client.event
async def on_member_join(member):
    channel = discord.util.get(member.Guild, name='general')
    await channel.send(f'Hey welcome to my server {member.mention}, hope you enjoy this server!')
      

"""
I put the keep_alive call outside because the function blocks it in your code.
And also removed client.close() to prevent your bot from closing
"""
keep_alive.keep_alive()
client.run(token)

For the dm command. Here it is:

@client.command()
async def dm(ctx, member:discord.Member=None):
    if member is None:
        return
    await ctx.send('Input your message:')
    def check(m):
        return m.author.id == ctx.author.id and m.content

    msg = await client.wait_for('message', check=check) # waits for message
    if msg:
        await member.create_dm().send(str(msg.content)) # sends message to user
        await ctx.send(f'Message has been sent to {member}nContent: `{msg.content}`')

Sorry, I’m kinda bad at explaining things, also for the delay. I’m also beginner so really I’m sorry

Answered By: Hiigari Yoshinova
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.