Discord command not running #9743
Unanswered
changcheng967
asked this question in
General
Replies: 1 comment
-
@changcheng967 You should ideally reformat your code to utilize codeblocks. This is not an issue with discord.py first and foremost. One notable issue that I want to discuss is the usage of passing |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My code is like
`import discord
from discord.ext import commands
from peewee import SqliteDatabase, Model, IntegerField, CharField
import random
intents = discord.Intents(
messages=True, # Enable message content intent
guilds=True, # Enable the guilds intent
members=True, # Enable the members intent
presences=True # Enable the presences intent
)
Create an instance of the bot
bot = commands.Bot(command_prefix='/', intents=intents)
Discord bot token
TOKEN = 'my token'
Set your database file name
DB_FILE = 'economy_database.db'
Set the currency symbol
CURRENCY_SYMBOL = 'Dollars'
database connection
db = SqliteDatabase(DB_FILE)
Define the User and Item models
class User(Model):
user_id = IntegerField(unique=True)
balance = IntegerField(default=0)
class Item(Model):
name = CharField(unique=True)
price = IntegerField()
Define the Lottery model
class Lottery(Model):
user_id = IntegerField()
ticket_number = IntegerField()
Initialize the database
db.connect()
db.create_tables([User, Item, Lottery], safe=True)
@bot.event
async def on_message(message):
print(f"Received message: {message.content}")
@bot.command(name='/ping', help='Check bot latency')
async def ping(ctx):
try:
latency = round(bot.latency * 1000)
await ctx.send(f'Pong! Latency: {latency}ms')
except Exception as e:
print(f"An error occurred in the ping command: {e}")
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name} ({bot.user.id})')
print('-------')
await update_bot_status()
@bot.event
async def on_message(message):
print(f"Received message: {message.content}")
async def update_bot_status():
await bot.change_presence(activity=discord.Game(name="made by changcheng967"))
@bot.command(name='balance', help='Check your balance')
async def balance(ctx):
user = get_or_create_user(ctx.author.id)
await ctx.send(f'Your balance: {user.balance} {CURRENCY_SYMBOL}')
@bot.command(name='shop', help='View available items in the shop')
async def shop(ctx):
items = Item.select()
shop_list = '\n'.join([f'{item.name} - {item.price} {CURRENCY_SYMBOL}' for item in items])
await ctx.send(f'Shop Items:\n{shop_list}')
@bot.command(name='buy', help='Buy an item from the shop')
async def buy(ctx, item_name: str):
user = get_or_create_user(ctx.author.id)
item = get_item(item_name)
@bot.command(name='sell', help='Sell an item to the shop')
async def sell(ctx, item_name: str):
user = get_or_create_user(ctx.author.id)
item = get_item(item_name)
@bot.command(name='lottery', help='Buy a lottery ticket')
async def lottery(ctx):
user = get_or_create_user(ctx.author.id)
if user.balance >= 50: # Assuming lottery ticket price is 50 coins
user.balance -= 50
user.save()
def get_or_create_user(user_id):
user, created = User.get_or_create(user_id=user_id)
return user
def get_item(item_name):
try:
item = Item.get(Item.name == item_name)
return item
except Item.DoesNotExist:
return None
#buying
try:
roblox_pass = Item.get(Item.name == 'Roblox Season Pass')
roblox_pass.price = 10000000
roblox_pass.save()
except Item.DoesNotExist:
# Create items if they don't exist
Item.create(name='Roblox Season Pass', price=10000000)
Item.create(name='Minecraft Java Edition Account', price=50000000)
Run the bot
bot.run(TOKEN)
`
but then the warning said WARNING discord.ext.commands.bot Privileged message content intent is missing, commands may not work as expected. I tryed to fix it but it's still there, when I tried to use the command, there is no command when I type "/"
Beta Was this translation helpful? Give feedback.
All reactions