K
K
Konstantin2021-08-02 14:54:27
Python
Konstantin, 2021-08-02 14:54:27

Not sending a chat message when joining a server?

There is a simple bot that can respond to "$mute" commands, and that's it. Then I decided to force the bot to write a regular message to the main chat, but something went wrong and I didn’t get a message at all.

Here is the code:

import discord
from discord.ext import commands
from config import settings
import asyncio
from asyncio import sleep
bot = commands.Bot(command_prefix = settings['prefix'])
@bot.command()
# async def hello(ctx):
#     author = ctx.message.author

#     await ctx.send(f'Приветствую, {author.mention}!')

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

@bot.event
async def on_member_join(member):
    channel = client.get_channel(673495471288746014)
    await channel.send('hello,', {member.mention})

@commands.has_permissions(manage_roles=True, ban_members=True, kick_members=True)
async def mute(ctx, user: discord.Member, time: int, reason):
    role = user.guild.get_role(871675273588920350)
    await ctx.send(f'{user} получил мут на {time} минут по причине: {reason}')
    await user.add_roles(role)
    await user.move_to(None)
    await asyncio.sleep(time * 60)
    await user.remove_roles(role)

bot.run(settings['token'])

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question