#Fix discord bot program bug
14 messages · Page 1 of 1 (latest)
Fix discord bot program bug
方便
can you send entire code
你是不是大陆的
东南亚的一个国家
ok
import discord
from discord import app_commands
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True
class MyBot(commands.Bot):
def init(self):
super().init(command_prefix="!", intents=intents)
async def setup_hook(self):
self.tree.add_command(ping)
self.tree.add_command(hello)
await self.tree.sync()
bot = MyBot()
@bot.event
async def on_ready():
print(f'Logged on as {bot.user}!')
@bot.event
async def on_message(message):
if message.author == bot.user:
return
@bot.command()
async def ping(ctx):
await ctx.send('pong')
@bot.tree.command(name="ping", description="Returns pong!")
async def ping(interaction: discord.Interaction):
await interaction.response.send_message("pong")
@bot.tree.command(name="hello", description="Says hello to the user.")
async def hello(interaction: discord.Interaction):
await interaction.response.send_message(f"Hello, {interaction.user.name}!")
bot.run('TOKEN')