В настоящее время я использую python для написания кода моего первого бота Discord. Пытаясь написать команду, я увидел, что не могу этого сделать. Этот код:
import os
import random
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
TOKEN = 'NzQxMjA2OTQzMDc4ODA5NjEy.Xy0Mwg.Shkr9hHvkn-y4l5ye1yTHYM3rQo'
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!')
pp = commands.Bot(command_prefix='!')
messages = ["hello", "hi", "how are you?"]
@pp.command(name = "swear")
async def swear(ctx):
await ctx.send(rand.choice(messages))
client.run(TOKEN)
ничего не выводит в приложении Discord, когда я набираю! Swear. Бот находится в сети и нормально работает с другими кодами, такими как:
@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!')
Вот полный код:
import discord
import os
import random
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
TOKEN = (##my token spelled out)
client = discord.Client()
@client.event
async def on_ready():
print('im 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('Hi there!')
elif message.content.startswith("Is Ethan's mum gay?"):
await message.channel.send("Yep, 100%!")
elif message.content.startswith("What are you doing?"):
await message.channel.send(f"Step {message.author}")
elif 'happy birthday' in message.content.lower():
await message.channel.send('Happy Birthday! ??')
@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!')
pp = commands.Bot(command_prefix='!')
messages = ["hello", "hi", "how are you?"]
@pp.command(name = "swear")
async def swear(ctx):
await ctx.send(rand.choice(messages))
client.run(TOKEN)
Кто-нибудь знает, как я могу решить мою проблему?