A3: Trolling a Discord Command Bot#
Choose Social Media Platform: Reddit | Discord | Bluesky | No Coding
In this assignment, your job will be to modify the slash command bot below (see section Demo: Trolling a Discord Command Bot) and make your own version of a reply bot (look for the TODO
section below). Then after you’ve modified it, see if you can troll it. At the end, you will have some reflection questions to answer.
When you are done, you will need to download this file (file menu -> download) and turn it in on Canvas.
Below is the code for the first command bot from the book:
It is a slash command called
do_action
which will ask us to provide an “action”The bot will then reply, “I will now ____” (where the ___ is the action the user provided).
Subject: “Wanting bot response”, body: “I want you to ___” (where the ___ is some action)
then the bot will reply, “I will now ____” (where the ___ is that same action).
Running a slash command#
To run the action, in discord start typing /
and you should be able to chose the do_action
command and then enter the text to do the action._
Command Bot#
First we need to do our Discord setup (using the discord interactions
library, which helps us set up commands):
# Load some code called "interactions" that will help us make Discord commands
import interactions
# Load another library that helps the bot work in Jupyter Noteboook
import nest_asyncio
nest_asyncio.apply()
(optional) make a fake Discord connection with the fake_discord_interactions library
For testing purposes, we’ve added this line of code, which loads a fake version of the “interactions” Discord library, so it wont actually connect to Discord. If you want to try to actually connect to Discord, don’t run this line of code.
%run ../../../../fake_apis/fake_discord_interactions.ipynb
To use this on your real Discord account, copy your developer access passwords into the discord_keys.py file.
import discord_keys
# TODO: put the server/guild id you want your bot command to work on below
server_id = "123456"
Create a command bot#
We will make a slash command bot
TODO: Modify this section (create a slash command)#
This code starts a bot that creates a discord slash command on the server with the server_id
we saved above.
The bot logs into discord, then starts (and displays a message showing it has started)
The initial version of the bot then creates a slash command called “do_action” which requires users to enter a piece of text for the “action.”
The initial version of the bot then creates a post that says “I will now ___” where the “___” is the action the user provided.
You must must modify at least one thing in the code below. You could change the name
of the slash_command
, or the name
of the action
, or you could change the code that makes the post (ctx.send(...)
), or you could change both.
# Log into discord
bot = interactions.Client(token=discord_keys.discord_token)
# Listen for when the bot is logged in and ready, then print that the bot has started
@interactions.listen()
async def on_ready():
print("The bot has started running")
# Define a slash command called "do_action" for the given server_id
@interactions.slash_command(name="do_action", description="A bot that does what it's told.", scopes=[server_id])
# make the slash command require an option called "action"
@interactions.slash_option(
name="action",
description="Action for bot to do",
required=True,
opt_type=interactions.OptionType.STRING
)
# Define a function to call when the "/do_action" command is used
async def do_action_function(ctx: interactions.SlashContext, action: str):
print('We recieved the following action: "' + action + '"')
# Make a post using the "action" provided by the user
await ctx.send("I will now " + action)
# For testing purposes, we close the bot after one response
# normally we wouldn't stop and leave the bot running so it
# can continue responding
print("Bot is now stopping")
bot.stop()
# start running your bot
bot.start()
The bot has started running
We recieved the following action: "jump"
Bot is now stopping
Reflection questions#
What changes did you make to the command bot?
TODO: Write your answer here
How could you troll this bot? Give an example of a message that would let you troll it. Or, if you don’t think it can be trolled, explain why.
TODO: Write your answer here
What limitations does trying to prevent trolling put on your ability to create a bot? (write at least 3 sentences)
TODO: Write at least 3 sentences here
Pick two ethics frameworks and compare how they might evaluate the responsibility of someone who is creating a command bot? (write at least 6 sentences total)
TODO: Write at least 6 sentences here
Pick two ethics frameworks and compare how they might evaluate the responsibility of someone who is considering trolling a command bot? (write at least 6 sentences total)
TODO: Write at least 6 sentences here