Jump to content


Photo

Python scripts explanation


  • Please log in to reply
2 replies to this topic

#1 dam

dam

    Newbie

  • Members
  • 9 posts
  • Gender:Male
  • Location:Padua, Italy

Posted 03 April 2021 - 05:07 PM

Can someone explain to me what each instruction in the discord bot python scripts work? (this guide here) I kinda want to try to customise my bot code directory position, but i don't know how the script works. I see that it reads the file directly in the guide but I'm don't know python enough to make sense of it



#2 m3z

m3z

    Newbie

  • Members
  • 1 posts
  • Gender:Male
  • Location:Paris

Posted 05 April 2021 - 09:33 AM

Hi dam

You mean this script below ?

It doesn't matter.
You can locate your script where ever you want.
The script connect to discord server from where it is on the disc.

 

Do a try

#!/usr/bin/python3.6

import os
import discord
from dotenv import load_dotenv

load_dotenv()
token = os.getenv('DISCORD_TOKEN')

client = discord.Client()

@client.event
async def on_member_join(member):
    await member.create_dm()
    await member.dm_channel.send(
        f'Hi {member.name}, welcome to my Discord server!'
    )

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

    if message.content == '!heliobot':
        await message.channel.send(f'Hello, how are you today?')

client.run(token)

Edited by m3z, 05 April 2021 - 09:33 AM.


#3 dam

dam

    Newbie

  • Members
  • 9 posts
  • Gender:Male
  • Location:Padua, Italy

Posted 06 April 2021 - 10:49 AM

 

Hi dam

You mean this script below ?

It doesn't matter.
You can locate your script where ever you want.
The script connect to discord server from where it is on the disc.

 

Do a try

#!/usr/bin/python3.6

import os
import discord
from dotenv import load_dotenv

load_dotenv()
token = os.getenv('DISCORD_TOKEN')

client = discord.Client()

@client.event
async def on_member_join(member):
    await member.create_dm()
    await member.dm_channel.send(
        f'Hi {member.name}, welcome to my Discord server!'
    )

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

    if message.content == '!heliobot':
        await message.channel.send(f'Hello, how are you today?')

client.run(token)

No, i mean the start.py and stop.py scripts, that make the bot start and stop






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users