MCPcopy Create free account
hub / github.com/caesarHQ/textSQL / run_discord_bot

Function run_discord_bot

api/discordbot/bot.py:17–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15
16
17def run_discord_bot():
18 TOKEN = 'DISCORD_BOT_TOKEN'
19 intents = discord.Intents.default()
20 intents.message_content = True
21 client = discord.Client(intents=intents)
22 tree = app_commands.CommandTree(client)
23
24 @client.event
25 async def on_ready():
26 print(f'{client.user} is now running!')
27
28 @tree.command(name="query", description="Query census gpt")
29 async def query_command(interaction: Interaction):
30 await interaction.response.defer()
31 await interaction.response.send_message("Hello!")
32
33 @client.event
34 async def on_message(message):
35 if message.author == client.user:
36 return
37
38 username = str(message.author)
39 user_message = str(message.content)
40 channel = str(message.channel)
41
42 print(f'{username} said: "{user_message}" ({channel})')
43
44 if user_message[0] == '?':
45 user_message = user_message[1:]
46 await send_message(message, user_message, is_private=True)
47 else:
48 await send_message(message, user_message, is_private=False)
49
50 client.run(TOKEN)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected