[英]Disnake / discord.py How to to edit a bot embed after multiple days?
[英]Disnake/Discord.py How do you send a embed
#imports
import asyncio
import json
import os
import random
import discord
import disnake
from discord import *
from disnake.ext import commands
from disnake.enums import ButtonStyle
bot = commands.Bot(command_prefix="/")
alredy_message = False
client=discord.Client()
async def on_ready(self,message):
print(f"Logged in as {self.user} (ID: {self.user.id})")
#account things
async def open_account(ctx):
user = ctx.author
users = await get_score()
with open("data_file.json", "r") as f:
users = json.load(f)
if str(user.id) in users:
return False
else:
users[str(user.id)]["score"] = 0
with open("data_file.json", "w") as f:
json.dump(users, f)
return True
async def get_score():
with open("data_file.json", "r") as f:
users = json.load(f)
return users
@bot.slash_command(
name="bal",
description="Check your balance",
guild_ids=[913544429703405608],
)
async def balance_check(ctx):
await open_account(ctx.author)
users = await get_score()
score = users[str(user.id)] = {}
score = users[str(user.id)]["score"]
embed = discord.Embed(title={ctx.author.name} + 's score', color=discord.Colour.red())
embed.add_field(name="Score", value=score)
await ctx.send(embed=embed)
@bot.slash_command(
name="game",
description="Play a game",
guild_ids=[913544429703405608]
)
#buttons
async def thiscommand(ctx):
inter = disnake.MessageInteraction
inter = disnake.MessageInteraction
user = ctx.author
with open("data_file.json", "r") as f:
users = json.load(f)
customer = json.loads(str(bot.user.id))
answer = random.randint(1,10)
embed = disnake.Embed(title="Guessing Game",color=0x7be3cb,description = "Guess a number randomly generated from 1-10")
# Defines a simple view of row buttons.
class RowButtons(disnake.ui.View):
def __init__(self):
super().__init__(timeout=60)
# Creates a row of buttons and when one of them is pressed, it will send a message with the number of the button.
@disnake.ui.button(label="1", style=ButtonStyle.primary)
async def first_button(self,ctx,Button,inter: disnake.MessageInteraction ):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 1:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 1:
await inter.edit_original_message(content="Too Low!")
if answer < 1:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="2", style=ButtonStyle.primary)
async def second_button(self,ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 2:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 2:
await inter.edit_original_message(content="Too Low!")
if answer < 2:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="3", style=ButtonStyle.primary)
async def third_button(self,ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 3:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 3:
await inter.edit_original_message(content="Too Low!")
if answer < 3:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="4", style=ButtonStyle.primary, row=1)
async def fourth_button(self,ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 4:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 4:
await inter.edit_original_message(content="Too Low!")
if answer < 4:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="5", style=ButtonStyle.primary, row=1)
async def fifth_button(self, ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 5:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 5:
await inter.edit_original_message(content="Too Low!")
if answer < 5:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="6", style=ButtonStyle.primary, row=1)
async def sixth_button(self,ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 6:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 6:
await inter.edit_original_message(content="Too Low!")
if answer < 6:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="7", style=ButtonStyle.primary, row=2)
async def seventh_button(self,ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 7:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 7:
await inter.edit_original_message(content="Too Low!")
if answer < 7:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="8", style=ButtonStyle.primary, row=2)
async def eighth_button(self,ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 8:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 8:
await inter.edit_original_message(content="Too Low!")
if answer < 8:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="9", style=ButtonStyle.primary, row=2)
async def nineth_button(self,ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 9:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer > 9:
await inter.edit_original_message(content="Too Low!")
if answer < 9:
await inter.edit_original_message(content="Too High!")
@disnake.ui.button(label="10", style=ButtonStyle.primary, row=3)
async def tenth_button(self,ctx,inter: disnake.MessageInteraction):
if alredy_message == False:
await inter.response.send_message("UHHH")
if answer == 10:
await inter.edit_original_message(content="Correct!")
await ctx.send("You just earned 1 gamebux!")
users[str(user.id)]["score"] += 1
with open("data_file.json", "w") as f:
json.dump(users, f)
if answer < 10:
await inter.edit_original_message(content="Too High!")
if answer > 10:
await inter.edit_original_message(content="Too Low!")
#running
view = RowButtons()
await inter.response.send_message(view=view,embed=embed)
bot.run("TOKEN")
我正在尝试制作一个机器人,它可以为您提供货币并为您提供游戏(只有一个)。 它会给你积分,但当我在 discord 中使用命令时,它不会发布游戏。 有人帮忙。 如果您发现货币和账户系统有任何问题,也请告诉我。 我刚刚开始学习 Discord.py 所以我还是个初学者,请有人帮忙,因为我已经尝试解决这个问题很长时间了。
这是在回答您的问题,您的问题是如何进行嵌入,但是在您的代码中,您导入了斜杠命令和其他按钮安装,这可能会导致您的机器人由于错误安装其模块而无法工作!
关于嵌入
@bot.command()
async def testing(ctx):
testembed = discord.Embed(title="Test", description="this is a test message", color=0x0000)
await ctx.send(embed=testembed)
#you can leave title blank like "" if you need no titles
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.