Replaced ? commands with slash commands

This commit is contained in:
Marco Loewe 2023-11-14 10:21:23 +01:00
parent d2d8d8a67b
commit 3a0c2ac8ab

24
bot.py
View File

@ -4,6 +4,7 @@ import subprocess
import json import json
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord import app_commands
with open('config.json', 'r') as f: with open('config.json', 'r') as f:
@ -15,24 +16,27 @@ if exists('config.local.json'):
intents = discord.Intents.default() intents = discord.Intents.default()
intents.message_content = True intents.message_content = True
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
description = '''Bot to end all bots''' description = '''Bot to end all bots'''
bot = commands.Bot(command_prefix='?', description=description, intents=intents) # bot = commands.Bot(command_prefix='?', description=description, intents=intents)
@bot.event @client.event
async def on_ready(): async def on_ready():
print(f'Logged in as {bot.user}') await tree.sync(guild=discord.Object(id='745287426402156555'))
print(f'Logged in as {client.user}')
print('------') print('------')
@bot.command() @tree.command(name = 'cool', description = 'Check how cool you are!', guild=discord.Object(id='745287426402156555'))
async def cool(ctx): async def cool(ctx):
cool_factor = round(random.uniform(0, 100), 2) cool_factor = round(random.uniform(0, 100), 2)
await ctx.send(f'{ctx.author} is {cool_factor}% cool!') await ctx.response.send_message(f'{ctx.author} is {cool_factor}% cool!')
@bot.command() # @bot.command()
async def update(ctx): # async def update(ctx):
subprocess.Popen('./update.sh') # subprocess.Popen('./update.sh')
print(f'Updating, see you on the other side') # print(f'Updating, see you on the other side')
bot.run(data['token']) client.run(data['token'])